Example usage for org.apache.mahout.cf.taste.impl.recommender.svd SVDRecommender recommend

List of usage examples for org.apache.mahout.cf.taste.impl.recommender.svd SVDRecommender recommend

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.impl.recommender.svd SVDRecommender recommend.

Prototype

@Override
public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException 

Source Link

Document

Default implementation which just calls Recommender#recommend(long,int,org.apache.mahout.cf.taste.recommender.IDRescorer) , with a org.apache.mahout.cf.taste.recommender.Rescorer that does nothing.

Usage

From source file:de.apaxo.bedcon.AnimalFoodRecommender.java

License:Open Source License

public void initRecommender() {
    try {/*from   w  w w.ja  va2  s.  c  om*/

        PearsonCorrelationSimilarity pearsonSimilarity = new PearsonCorrelationSimilarity(model);

        // Java: Similarity between Wolf and Bear: 0.8196561646738477
        // R: corr(c(8,3,1),c(8,7,2)): 0.8196562
        System.out.println("Similarity between Wolf and Bear: "
                + pearsonSimilarity.userSimilarity(id2thing.toLongID("Wolf"), id2thing.toLongID("Bear")));
        // Similarity between Wolf and Rabbit: -0.6465846072812313
        // R: cor(c(8,3,1),c(2,1,10)): -0.6465846
        System.out.println("Similarity between Wolf and Rabbit: "
                + pearsonSimilarity.userSimilarity(id2thing.toLongID("Wolf"), id2thing.toLongID("Rabbit")));
        // Similarity between Wolf and Pinguin: -0.24019223070763077
        // R: cor(c(8,3,1),c(2,10,2)): -0.2401922
        System.out.println("Similarity between Wolf and Pinguin: "
                + pearsonSimilarity.userSimilarity(id2thing.toLongID("Wolf"), id2thing.toLongID("Pinguin")));

        GenericUserBasedRecommender recommender = new GenericUserBasedRecommender(model,
                new NearestNUserNeighborhood(3, pearsonSimilarity, model), pearsonSimilarity);
        for (RecommendedItem r : recommender.recommend(id2thing.toLongID("Wolf"), 3)) {
            // Pork:
            // (0.8196561646738477 * 8 + (-0.6465846072812313) * 1) / (0.8196561646738477 + (-0.6465846072812313)) = 34,15157 ~ 10
            // Grass:
            // (2*(-0.24019223070763077)+7*(-0.6465846072812313)) / ((-0.24019223070763077) + (-0.6465846072812313)) = 5,65
            // Corn:
            // (2*(-0.24019223070763077)+2*(0.8196561646738477)) / (-0.24019223070763077+0.8196561646738477) = 2
            System.out.println("UserBased: Wolf should eat: " + id2thing.toStringID(r.getItemID()) + " Rating: "
                    + r.getValue());
        }
        SVDRecommender svdrecommender = new SVDRecommender(model, new SVDPlusPlusFactorizer(model, 4, 1000));
        for (RecommendedItem r : svdrecommender.recommend(id2thing.toLongID("Sheep"), 3)) {
            System.out.println("SVD: Sheep should eat: " + id2thing.toStringID(r.getItemID()) + " Rating: "
                    + r.getValue());
        }
    } catch (TasteException e) {
        e.printStackTrace();
    }
}

From source file:edu.carleton.comp4601.cf.dao.SimpleDataRecommender.java

License:Open Source License

public void initRecommender() {
    try {//from w w  w. j  a  v  a 2 s.c om

        PearsonCorrelationSimilarity pearsonSimilarity = new PearsonCorrelationSimilarity(model);

        System.out.println("Similarity between Alice and User1: "
                + pearsonSimilarity.userSimilarity(id2thing.toLongID("Alice"), id2thing.toLongID("User1")));
        System.out.println("Similarity between Alice and User2: "
                + pearsonSimilarity.userSimilarity(id2thing.toLongID("Alice"), id2thing.toLongID("User2")));
        System.out.println("Similarity between Alice and User3: "
                + pearsonSimilarity.userSimilarity(id2thing.toLongID("Alice"), id2thing.toLongID("User3")));

        GenericUserBasedRecommender recommender = new GenericUserBasedRecommender(model,
                new NearestNUserNeighborhood(3, pearsonSimilarity, model), pearsonSimilarity);
        for (RecommendedItem r : recommender.recommend(id2thing.toLongID("Alice"), 3)) {
            System.out.println("UserBased: Alice should like: " + id2thing.toStringID(r.getItemID())
                    + " Rating: " + r.getValue());
        }
        SVDRecommender svdrecommender = new SVDRecommender(model, new SVDPlusPlusFactorizer(model, 4, 1000));
        for (RecommendedItem r : svdrecommender.recommend(id2thing.toLongID("User1"), 3)) {
            System.out.println("SVD: User1 should like: " + id2thing.toStringID(r.getItemID()) + " Rating: "
                    + r.getValue());
        }
    } catch (TasteException e) {
        e.printStackTrace();
    }
}