import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;
import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.apache.mahout.cf.taste.recommender.Recommender;
import org.apache.mahout.cf.taste.similarity.UserSimilarity;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * Created by cheyulin on 10/19/16.
 */
public class CollaborativeFiltering {
    public static void main(String[] args) throws IOException, TasteException {

        File modelFile = new File("train.txt");

        DataModel model = new FileDataModel(modelFile);

        UserSimilarity similarity = new PearsonCorrelationSimilarity(model);

        UserNeighborhood neighborhood = new NearestNUserNeighborhood(4, similarity, model);

        Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);

        //给用户1推荐4个物品
        List<RecommendedItem> recommendations = recommender.recommend(436821, 1);

        for (RecommendedItem recommendation : recommendations) {
            System.out.println(recommendation);
        }
    }


}

@@ -265,32 +265,196 @@
 sedRecommender;%0A
+import org.apache.mahout.cf.taste.impl.recommender.svd.ExpectationMaximizationSVDFactorizer;%0Aimport org.apache.mahout.cf.taste.impl.recommender.svd.SVDRecommender;%0A
 import org.apach
@@ -1427,24 +1427,146 @@
 milarity);%0A%0A
+%0A        SVDRecommender svdrecommender=new SVDRecommender(model,new ExpectationMaximizationSVDFactorizer(model,4,1000));%0A%0A
         //%E7%BB%99%E7%94%A8
@@ -1570,12 +1570,17 @@
 /%E7%BB%99%E7%94%A8%E6%88%B7
+43682
 1%E6%8E%A8%E8%8D%90
-4
+1
 %E4%B8%AA%E7%89%A9%E5%93%81%0A

update svd recommender