예제 #1
0
  /** 基本算法 */
  public static void demo1(DataModel m) throws Exception {
    System.out.println("==============用户,打分,平均差值(0)==============");

    // 推荐结果
    UserSimilarity s = MySimilarity.getPearsonCorrelation(m);
    UserNeighborhood n = MyNeighborhood.getNearestN(m, s, 2);
    RecommenderBuilder rb = MyRecommender.userBuilder(s, n);
    MyRecommender.showItems(rb.buildRecommender(m).recommend(26, 1));

    RecommenderEvaluator e = new AverageAbsoluteDifferenceRecommenderEvaluator();
    double score = e.evaluate(rb, null, m, 0.9, 1.0); // testing data, all
    // data
    System.out.println("算法得分: " + score);
    System.out.println();
  }
예제 #2
0
  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();
  }
예제 #3
0
  public static void demo2(DataModel m) throws Exception {
    System.out.println("==============用户,打分,均方根(0)==============");

    // 推荐结果
    UserSimilarity s = MySimilarity.getPearsonCorrelation(m);
    UserNeighborhood n = MyNeighborhood.getNearestN(m, s, 2);
    RecommenderBuilder rb = MyRecommender.userBuilder(s, n);
    MyRecommender.showItems(rb.buildRecommender(m).recommend(26, 1));

    // RandomUtils.useTestSeed();
    RecommenderEvaluator e = new RMSRecommenderEvaluator();
    double score = e.evaluate(rb, null, m, 0.7, 0.3); // testing data, all
    // data
    System.out.println("算法得分: " + score);

    System.out.println();
  }
예제 #4
0
  public static void demo4(DataModel m) throws Exception {
    System.out.println("==============用户,打分,fast,平均差值(0)==============");

    // 推荐结果
    UserSimilarity s = MySimilarity.getPearsonCorrelation(m);
    UserNeighborhood n = MyNeighborhood.getNearestN(m, s, 2);
    RecommenderBuilder rb = MyRecommender.userBuilder(s, n);
    MyRecommender.showItems(rb.buildRecommender(m).recommend(1, 1));

    // 算法得分
    // RandomUtils.useTestSeed();
    RecommenderEvaluator e = new AverageAbsoluteDifferenceRecommenderEvaluator();
    DataModelBuilder db = MyDataModel.createPrefDataModelBuilder();
    double score = e.evaluate(rb, db, m, 0.7, 1.0); // testing data, all data
    System.out.println("算法得分: " + score);

    System.out.println();
  }