热线电话:13121318867

登录
2020-11-20 阅读量: 1959
基于物品/用户的协同过滤算法如何做模型评估?

评估指标,均方根误差

使用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)

发表评论
85691082
2020-11-23

谢谢老师

0.0000 0 0 回复
推荐帖子
条评论