liting李

2020-11-20   阅读量: 1636

Python

基于物品/用户的协同过滤算法如何做模型评估?

扫码加入数据分析学习群

评估指标,均方根误差

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


添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
29.6486 1 1 关注作者 收藏

评论(1)

85691082
2020-11-23

谢谢老师

0.0000 0 0 回复

推荐课程

推荐帖子