gpt4 book ai didi

python - 使用 Surprise SVD++ 算法获取所有用户的预测

转载 作者:行者123 更新时间:2023-12-04 01:29:16 27 4
gpt4 key购买 nike

我想使用 Surprise 构建一个简单的书籍推荐器图书馆和购买/不购买作为评级值(而不是经典的 1 到 5)。

我的问题是我想在我的 whole dataset 上训练所以我可以得到对 ALL users 的预测,所以我正在检查这个惊喜示例 (examples/top_n_recommendations.py) :

from collections import defaultdict

from surprise import SVD
from surprise import Dataset

def get_top_n(predictions, n=10):
...

# First train an SVD algorithm on the movielens dataset.
data = Dataset.load_builtin('ml-100k')
trainset = data.build_full_trainset()
algo = SVD()
algo.fit(trainset)

# Then predict ratings for all pairs (u, i) that are NOT in the training set.
testset = trainset.build_anti_testset()
predictions = algo.test(testset)

top_n = get_top_n(predictions, n=10)

# Print the recommended items for each user
for uid, user_ratings in top_n.items():
print(uid, [iid for (iid, _) in user_ratings])

我的疑问是,如果它在整个数据集上训练,为什么要构建反测试?
如何获得所有用户的推荐,同时在我的整个数据集上训练算法?

最佳答案

使用 Surprise 库,您只能获得训练集中用户的预测。反测试集包含所有对 (用户,项目)不在训练集中的项目,因此它会推荐用户过去未与之交互的项目。

关于python - 使用 Surprise SVD++ 算法获取所有用户的预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61339532/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com