我正在尝试使用以下代码使用示例数据“intro.csv”运行KnnItemBasedRecommender,但是我得到了空集作为结果。
public static void main(String[] args) throws Exception {
DataModel model = NeuvidisData.convertToDataModel();
//RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
@Override
public Recommender buildRecommender(DataModel model) {
ItemSimilarity similarity = new LogLikelihoodSimilarity(model);
Optimizer optimizer = new ConjugateGradientOptimizer();
return new KnnItemBasedRecommender(model, similarity, optimizer, 2);
}
};
Recommender rec = recommenderBuilder.buildRecommender(model);
List<RecommendedItem> rcList = rec.recommend(1, 2);
for(RecommendedItem item:rcList)
{
System.out.println("item:");
System.out.println(item);
}
}
有人能帮助我吗?
答案 0 :(得分:0)
可能是因为您的数据太小或太稀疏而无法使用此算法为用户1提供建议。没有数据就很难说。
答案 1 :(得分:0)
以下代码对我有用。
ItemSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
Optimizer optimizer = new ConjugateGradientOptimizer();
Recommender recommender = new KnnItemBasedRecommender(dataModel, similarity, optimizer, 5);
使用PearsonCorrelationSimilarity而不是LogLikelihoodSimilarity。
此解决方案可能适用于特定数据集。因此,此解决方案基于您的数据集。