Closed Ermeimei closed 5 years ago
I find the solution.Thanks to Mr Hong. If you use RecommenderJob to conduct an algorithm by reading the configuration file, we can reproduce results by adding this (rec.random.seed=1) into the configuration file. If you specify the configurations in the program,you should add this code Randoms.seed(1L)
in the program.
I follow the instruction that initialization of the random number is set by the the 'rec.random.seed' configuration.But each time I run my program ,it gave different result. This is my code:
public static void recommendingTest() throws LibrecException { // build data model Configuration conf = new Configuration(); conf.set("dfs.data.dir", "data/movielens/ml-100k"); conf.set("data.input.path", "ratings.txt"); conf.set("rec.random.seed","1"); conf.set("rec.recommender.verbose","true"); TextDataModel dataModel = new TextDataModel(conf); dataModel.buildDataModel(); // build recommender context RecommenderContext context = new RecommenderContext(conf, dataModel); // build similarity conf.set("rec.recommender.similarity.key" ,"item"); conf.setBoolean("rec.recommender.isranking", true); conf.setInt("rec.similarity.shrinkage", 10); RecommenderSimilarity similarity = new CosineSimilarity(); similarity.buildSimilarityMatrix(dataModel); context.setSimilarity(similarity); // build recommender conf.set("rec.neighbors.knn.number", "50"); Recommender recommender = new ItemKNNRecommender(); recommender.setContext(context); // run recommender algorithm recommender.recommend(context); // evaluate the recommended result RecommenderEvaluator ndcgEvaluator = new NormalizedDCGEvaluator(); ndcgEvaluator.setTopN(30); double ndcgValue = recommender.evaluate(ndcgEvaluator); System.out.println("ndcg:" + ndcgValue); List recommendedItemList = recommender.getRecommendedList();
GenericRecommendedFilter filter = new GenericRecommendedFilter();
List userIdList = new ArrayList();
userIdList.add("196");
filter.setUserIdList(userIdList);
recommendedItemList = filter.filter(recommendedItemList);
Map<String,Double> propRec = new HashMap<String,Double>();
for(RecommendedItem item: recommendedItemList) {
propRec.put(item.getItemId(),item.getValue());
}
CommonMethods.sortDoubleMap(propRec);
}
Two different results are as follow:
ndcg:0.31936048384981075 50=25.283366556667033 100=24.944878127693837 181=24.567060984693313 98=24.55614612533019 127=24.50435505248202 1=24.46178325820936 174=24.345619275053057 172=24.326974665385197 258=24.294352559184205 210=24.226078418472728
ndcg:0.3323971752269902 50=23.576304545467604 100=23.1964687349119 181=23.01336420205977 174=23.01040673256511 79=22.454712075943636 98=22.427443453029632 204=22.39011405365638 210=22.299173539563625 56=22.297498696999842 237=22.283066885242206
Thanks!