两个特定用户之间的余弦相似度为 1.0,但他们对同一项目有不同的评分
作者: deil87创建于 2024年8月20日更新于 2024年8月22日
import urllib.request
urllib.request.urlretrieve("http://files.grouplens.org/datasets/movielens/ml-1m.zip", "ml-1m.zip")
reader = Reader(rating_scale=(1, 5)) data_full_lr_20k = data_full_lr[:20000] data_full = Dataset.load_from_df(data_full_lr_20k[["user", "item", "label"]], reader)
trainset_full, testset_full = train_test_split(data_full, test_size=0.25, random_state=42)
Then I'm running my new custom algo:
bsl_options = {"method": "als", "n_epochs": 5, "reg_u": 12, "reg_i": 5} sim_options = { "name": "cosine", "user_based": True, # compute similarities between users }
algo = MyAlgorithm(bsl_options=bsl_options, sim_options=sim_options)
train and test algorithm.
algo.fit(trainset_full) predictions = algo.test(testset_full)
Compute and print Root Mean Squared Error
accuracy.rmse(predictions, verbose=True)
内容来源: NicolasHug/Surprise