【问题标题】:Recommending users for other users based on their preferences by using Apache-mahout使用 Apache-mahout 根据用户的偏好为其他用户推荐用户
【发布时间】:2015-07-30 07:42:52
【问题描述】:

这是我在 stackoverflow.com 上的第一个问题,如果我犯了任何错误,请对此深表歉意。

现在,我正在尝试使用 apache-mahout 在 java 中创建推荐引擎。我有一个如下所示的输入文件(当然它会大得多):

 userID1 ItemID1  Rating1
 userID1 ItemID2  Rating2
 userID2 ItemID1  Rating3
 userID2 ItemID3  Rating4
 userID3 ItemID4  Rating5
 userID4 ItemID2  Rating6

我想做的是针对每个用户,我想根据他们对项目的评分推荐其他一些用户。可以说,在我的程序结束时,输出将是

userID1  similar to UserID2  with score of 0.8 (This score could be a value between 0 and 1 or a percentage  only requirement is being reasonable)
userID1  similar to userID3  with score of 0.7
userID2  similar to UserID1  with score of 0.8
userID2  similar to userID4  with score of 0.5
userID3  similar to userID1  with score of 0.7
userID4  similar to userID2  with score of 0.5

等等。为此,我编写了以下代码。

public void RecommenderFunction()
{
        DataModel model = new FileDataModel(new File("data/dataset.csv")); 
        UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
        UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0, similarity, model);
        UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);

        for(LongPrimitiveIterator users=model.getUserIDs();users.hasNext();)
        {
            long userId=users.nextLong();
            long[] recommendedUserIDs=recommender.mostSimilarUserIDs(userId, 100); // I want to find all similarUserIDs not a subset of it.Thats why I put 100 as a second argument.

            for(long recID:recommendedUserIDs)
            {
                System.out.println("user:"+userId+" similar with:"+recID);
            }

        }


}

这是我的dataset.csv 文件

1,10,1.0
1,11,2.0
1,12,5.0
1,13,5.0
1,14,5.0
1,15,4.0
1,16,5.0
1,17,1.0
1,18,5.0
2,10,1.0
2,11,2.0
2,15,5.0
2,16,4.5
2,17,1.0
2,18,5.0
3,11,2.5
3,12,4.5
3,13,4.0
3,14,3.0
3,15,3.5
3,16,4.5
3,17,4.0
3,18,5.0
4,10,5.0
4,11,5.0
4,12,5.0
4,13,0.0
4,14,2.0
4,15,3.0
4,16,1.0
4,17,4.0
4,18,1.0

这是我对该数据集的程序的结果:

user:1 similar with:2
user:1 similar with:3
user:1 similar with:4
user:2 similar with:1
user:2 similar with:3
user:2 similar with:4
user:3 similar with:2
user:3 similar with:1
user:3 similar with:4
user:4 similar with:3
user:4 similar with:1
user:4 similar with:2

我知道,由于我将 100 作为上述函数的第二个参数,因此推荐器会返回所有相似的用户对。我的问题从这里开始。我的程序能够告诉我哪些用户彼此相似。但是我找不到获得它们相似度分数的方法。我怎么能那样做?

编辑

我认为,皮尔逊系数相似度结果可用于验证推荐。我的逻辑错了吗?我的意思是,我用以下方式修改了上面的代码:

 public void RecommenderFunction()
    {
        // same as above.
            for(LongPrimitiveIterator users=model.getUserIDs();users.hasNext();)
            {
                // same as above.

                for(long recID:recommendedUserIDs)
                {
                    // confidence score of recommendation is the pearson correlation score of two users. Am I wrong?
                    System.out.println("user:"+userId+" similar with:"+recID+" score of: "+similarity.userSimilarity(userId, recID));
                }

            }


    }

【问题讨论】:

  • 欢迎来到 SO! :) 请通过tour 获取您的第一个闪亮徽章 :)

标签: java mahout recommendation-engine mahout-recommender


【解决方案1】:

这是一个好的开始。请记住,用户-用户相似度值用于创建项目推荐,因此您不能再次使用相似度分数来验证推荐质量。现在您有了用户-用户相似度得分,使用 Mahout 为您的所有用户生成项目推荐。当你有这个工作时,你可以通过对推荐者隐藏一些数据来测试推荐的质量,查看它对这些隐藏评级的预测,然后测量预测的接近程度。这是推荐器评估的一种形式(在许多形式中),它被称为预测准确性。一个常见的度量标准是 RMSE,或均方根误差。通过这样的指标,您将能够看到您的推荐人的表现如何。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 2018-01-31
    • 2011-09-09
    • 1970-01-01
    相关资源
    最近更新 更多