コード例 #1
0
  public static void main(String[] args) throws Exception {
    DataModel model =
        new GenericBooleanPrefDataModel(
            GenericBooleanPrefDataModel.toDataMap(new FileDataModel(new File("ua.base"))));

    RecommenderIRStatsEvaluator evaluator = new GenericRecommenderIRStatsEvaluator();
    RecommenderBuilder recommenderBuilder =
        new RecommenderBuilder() {
          @Override
          public Recommender buildRecommender(DataModel model) throws TasteException {
            UserSimilarity similarity = new LogLikelihoodSimilarity(model);
            UserNeighborhood neighborhood = new NearestNUserNeighborhood(10, similarity, model);
            return new GenericBooleanPrefUserBasedRecommender(model, neighborhood, similarity);
          }
        };
    DataModelBuilder modelBuilder =
        new DataModelBuilder() {
          @Override
          public DataModel buildDataModel(FastByIDMap<PreferenceArray> trainingData) {
            return new GenericBooleanPrefDataModel(
                GenericBooleanPrefDataModel.toDataMap(trainingData));
          }
        };
    IRStatistics stats =
        evaluator.evaluate(
            recommenderBuilder,
            modelBuilder,
            model,
            null,
            10,
            GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD,
            1.0);
    System.out.println(stats.getPrecision());
    System.out.println(stats.getRecall());
  }
コード例 #2
0
 /** statsEvaluator */
 public static void statsEvaluator(
     RecommenderBuilder rb, DataModelBuilder mb, DataModel m, int topn) throws TasteException {
   RecommenderIRStatsEvaluator evaluator = new GenericRecommenderIRStatsEvaluator();
   IRStatistics stats =
       evaluator.evaluate(
           rb, mb, m, null, topn, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
   // System.out.printf("Recommender IR Evaluator: %s\n", stats);
   System.out.printf(
       "Recommender IR Evaluator: [Precision:%s,Recall:%s]\n",
       stats.getPrecision(), stats.getRecall());
 }
コード例 #3
0
ファイル: Demo1.java プロジェクト: biubiu/mahout-demo
  public static void prefEvaluate(DataModel m) throws Exception {
    System.out.println("==============用户,打分,评估(1)==============");

    // 推荐结果
    UserSimilarity s = MySimilarity.getPearsonCorrelation(m);
    UserNeighborhood n = MyNeighborhood.getNearestN(m, s, 2);

    // 算法评估
    RecommenderBuilder rb = MyRecommender.userBuilder(s, n);
    RecommenderIRStatsEvaluator e = new GenericRecommenderIRStatsEvaluator();
    IRStatistics stats =
        e.evaluate(rb, null, m, null, 1, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1);
    System.out.println("查准率 : " + stats.getPrecision());
    System.out.println("全查率 : " + stats.getRecall());

    System.out.println();
  }
コード例 #4
0
ファイル: Demo1.java プロジェクト: biubiu/mahout-demo
  public static void noPrefEvaluate(DataModel m) throws Exception {
    System.out.println("==============用户,无打分,评估(1)==============");

    // 推荐结果
    UserSimilarity s = new LogLikelihoodSimilarity(m);
    UserNeighborhood n = MyNeighborhood.getNearestN(m, s, 2);

    // 算法评估
    RecommenderBuilder rb = MyRecommender.userBuilder(s, n);
    RecommenderIRStatsEvaluator e = new GenericRecommenderIRStatsEvaluator();
    DataModelBuilder db = MyDataModel.createNoPrefDataModelBuilder();
    IRStatistics stats =
        e.evaluate(rb, db, m, null, 1, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
    System.out.println("查准率 : " + stats.getPrecision());
    System.out.println("查全率 : " + stats.getRecall());

    System.out.println();
  }