推荐系统-02-评价技术

Posted 心飞翔<

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了推荐系统-02-评价技术相关的知识,希望对你有一定的参考价值。

下面简单通过在测试集上验证错误值 (JAVA)

package xyz.pl8.evaluatorintro;

import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.eval.RecommenderBuilder;
import org.apache.mahout.cf.taste.eval.RecommenderEvaluator;
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator;
import org.apache.mahout.cf.taste.impl.eval.RMSRecommenderEvaluator;
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.Recommender;
import org.apache.mahout.cf.taste.similarity.UserSimilarity;
import java.io.File;


public class EvaluatorIntro {
    public static void main(String[] args){
        try{
            DataModel model = new FileDataModel(new File("/home/hadoop/ua.base"));
            System.out.println(model);

            Recommender recommender = null;
            RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
                public Recommender buildRecommender(DataModel model) throws TasteException {
                    UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
                    UserNeighborhood neighborhood = new NearestNUserNeighborhood(100,  similarity, model );
                    return new GenericUserBasedRecommender(model, neighborhood, similarity);
                }
            };
            RecommenderEvaluator avgEvaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
            RecommenderEvaluator rmsEvaluator = new RMSRecommenderEvaluator();
            // 平均绝对值误差
            double avgScore = avgEvaluator.evaluate(recommenderBuilder, null, model, 0.7, 1.0);
            // 根方差错误
            double rmsScore = rmsEvaluator.evaluate(recommenderBuilder, null, model, 0.7, 1.0);

            System.out.println(avgScore);
            System.out.println(rmsScore);

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

以下是通过信息检索, 进行多维度的评价模型的优劣度(java)

package xyz.pl8.irevaluatorintro;


import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.eval.IRStatistics;
import org.apache.mahout.cf.taste.eval.RecommenderBuilder;
import org.apache.mahout.cf.taste.eval.RecommenderEvaluator;
import org.apache.mahout.cf.taste.eval.RecommenderIRStatsEvaluator;
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator;
import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator;
import org.apache.mahout.cf.taste.impl.eval.RMSRecommenderEvaluator;
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.Recommender;
import org.apache.mahout.cf.taste.similarity.UserSimilarity;

import java.io.File;

public class IREvaluatorIntro {
    public static void main(String[] args){
        try{
            DataModel model = new FileDataModel(new File("/home/hadoop/ua.base"));

            Recommender recommender = null;
            RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
                public Recommender buildRecommender(DataModel model) throws TasteException {
                    UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
                    UserNeighborhood neighborhood = new NearestNUserNeighborhood(100,  similarity, model );
                    return new GenericUserBasedRecommender(model, neighborhood, similarity);
                }
            };
            // 构造信息检索评估器
            RecommenderIRStatsEvaluator evaluator = new GenericRecommenderIRStatsEvaluator();

            // 进行评估
            IRStatistics stats = evaluator.evaluate(recommenderBuilder, null, model, null, 5, 0.7, 1.0);

            // 输出精确度,召回率, F1测度
            System.out.println(stats.getPrecision());
            System.out.println(stats.getRecall());
            System.out.println(stats.getF1Measure());




        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

以上是关于推荐系统-02-评价技术的主要内容,如果未能解决你的问题,请参考以下文章

推荐系统之评估方法和评价指标PR、ROC、AUC

转:TopN推荐系统——推荐的实现与推荐效果的评价指标

如何评估推荐系统的健康状况?

阶段一-02.分类,推荐,搜索,评价,购物车开发-第2章 商品推荐+搜索功能实现-2-4 搜索 - 编写商品相关查询service

阶段一-02.分类,推荐,搜索,评价,购物车开发-第1章 首页轮播图+分类功能实现-1-3 分类实现 - 加载与渲染大分类

阶段一-02.分类,推荐,搜索,评价,购物车开发-第4章 商品搜索功能开发-4-2 商品搜索 - 实现商品搜索功能

(c)2006-2024 SYSTEM All Rights Reserved IT常识