2020-11-20
阅读量:
2185
基于物品/用户的协同过滤算法如何做模型评估?
评估指标,均方根误差
使用sklearn的mean_square_error (MSE)函数,其中,RMSE仅仅是MSE的平方根
#这里只是想要考虑测试数据集中的预测评分, 因此,使用prediction[ground_truth.nonzero()]筛选出预测矩阵中的所有其他元素
from sklearn.metrics import mean_squared_error from math import sqrt def rmse(prediction, ground_truth): prediction = prediction[ground_truth.nonzero()].flatten() ground_truth = ground_truth[ground_truth.nonzero()].flatten() return sqrt(mean_squared_error(prediction, ground_truth))
print(train_data_matrix)
print(test_data_matrix)
print('User-based CF RMSE: ' + str(rmse(user_prediction, test_data_matrix)))
item_prediction = np.nan_to_num(item_prediction)
print('Item-based CF RMSE: ' + str(rmse(item_prediction, test_data_matrix)))
29.6486
1
1
关注作者
收藏
推荐帖子
0条评论
0条评论
0条评论

发表评论