/** 基本算法 */ 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(); }
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(); }
public static void demo3(DataModel m) throws Exception { System.out.println("==============用户,无打分,平均差值(0)=============="); // 推荐结果 UserSimilarity s = new LogLikelihoodSimilarity(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.createNoPrefDataModelBuilder(); double score = e.evaluate(rb, db, m, 0.7, 1.0); // testing data, all data System.out.println("算法得分: " + score); System.out.println(); }
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(); }
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(); }