0

我正在尝试使用下面的代码使用示例数据“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);
        }
    }

有谁能够帮助我?

4

2 回答 2

0

大概是因为您的数据太小或太稀疏,无法使用此算法为用户 1 提供建议。没有数据很难说。

于 2013-02-05T15:01:50.300 回答
0

以下代码对我有用。

                ItemSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
                Optimizer optimizer =  new ConjugateGradientOptimizer();
                Recommender recommender = new KnnItemBasedRecommender(dataModel, similarity, optimizer, 5);

使用 PearsonCorrelationSimilarity 而不是 LogLikelihoodSimilarity。

此解决方案可能适用于特定的数据集。因此,此解决方案基于您的数据集。

于 2013-07-04T04:54:52.723 回答