码迷,mamicode.com
首页 > 其他好文 > 详细

mahout学习(二)

时间:2014-09-02 13:57:14      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   数据   div   log   

下载测试数据:http://grouplens.org/datasets/movielens/   ml-100k.zip

public class TMahout02 {

    public static void main(String[] args) throws IOException, TasteException {

        //-配置并评估一个推荐程序-//
        RandomUtils.useTestSeed();
        DataModel model = new FileDataModel(new File("path/ua.base"));
        RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
        RecommenderBuilder builder = new RecommenderBuilder() {
            @Override
            public Recommender buildRecommender(DataModel dataModel) throws TasteException {
                UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
                //UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, dataModel);

                UserNeighborhood neighborhood =
                        new NearestNUserNeighborhood(2, similarity, dataModel);

                return new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
            }
        };
        double result = evaluator.evaluate(builder, null, model, 0.9, 1.0);
        System.out.println(result);

    }

}

 

mahout学习(二)

标签:style   blog   http   color   io   ar   数据   div   log   

原文地址:http://www.cnblogs.com/spacewalk/p/3951175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!