我正在遵循以下代码示例:
RandomUtils.useTestSeed();
DataModel model = new FileDataModel(new File(file));
RecommenderIRStatsEvaluator evaluator = new GenericRecommenderIRStatsEvaluator();
RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
public Recommender buildRecommender(DataModel model)
throws TasteException {
UserSimilarity similarity = new PearsonCorrelationSimilarity(
model);
UserNeighborhood neighborhood = new NearestNUserNeighborhood(2,
similarity, model);
return new GenericUserBasedRecommender(model, neighborhood,
similarity);
}
};
IRStatistics stats = evaluator.evaluate(recommenderBuilder, null,
model, null, 4, 4, 0.5);
System.out.println(stats.getPrecision());
System.out.println(stats.getRecall());
文件中的数据是:
1,101,5.0
1,102,3.0
1,103,2.5
2,101,2.0
2,102,2.5
2,103,5.0
2,104,2.0
3,101,2.5
3,104,4.0
3,105,4.5
3,107,5.0
4,101,5.0
4,103,3.0
4,104,4.5
4,106,4.0
5,101,4.0
5,102,3.0
5,103,2.0
5,104,4.0
5,105,3.5
5,106,4.0
在数据文件上运行上面的代码时,我得到了
java.lang.IllegalArgumentException: Illegal precision: NaN 为什么会这样?我在这里找到了一些相关的东西,但它是在 2009 年发布的,无法解释我的困惑。