【Surprise库学习】2. 评价指标

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qiqi123i/article/details/87992348

在Surprise库里面,由surprise.accuracy提供推荐系统的评价指标,一共有三种,分别是RMSE、MAE以及FCP


RMSE (lower is better)均方根误差

MSE(lower is better)均方误差

RMSE公式

MSE的公式:即RMSE不开根式

方法surprise.accuracy.rmse(predictions, verbose=True)
其中,predictions是list,结构在surprise库里面是[uid,iid,true_r,est_r,details]格式的,verbose=True会输出数值
调用
accuracy.rmse(predictions)
自己写

import numpy as np
predictions = [[1,1,2,4],[1,2,2,4],[1,3,2,4]]#uid,iid,true_rating,est_rating
mse = np.mean([float((true_r - est)**2) for (_,_,true_r,est) in predictions])#不要漏了这个[]

rmse = np.sqrt(mse)
print(mse)
print(rmse)

结果是4.0和2.0


MAE(lower is better)平均绝对误差

公式

方法surprise.accuracy.mae(predictions, verbose=True)
其中,predictions是list,结构在surprise库里面是[uid,iid,true_r,est_r,details]格式的,verbose=True会输出数值
调用
accuracy.mae(predictions)

关于RMSE和MAE两个指标的优缺点,Netflix认为RMSE加大了对预测不准的用户物品的评分的惩罚(平方项的惩罚),因而对系统的评测更加苛刻。研究表明,如果评分系统是基于整数建立的(即用户给的评分都是整数),那么对预测结果取整会降低MAE的误差。出自文章Major components of the Gravity Recommendation System
自己写

import numpy as np
predictions = [[1,1,2,4],[1,2,2,4],[1,3,2,4]]#uid,iid,true_rating,est_rating
mae = np.mean([float(abs(true_r - est)) for (_,_,true_r,est) in predictions])#不要漏了这个[]

print(mae)

结果是2.0


FCP(higher is better)

公式

出自文章Collaborative Filtering on Ordinal User Feedback
方法surprise.accuracy.fcp(predictions, verbose=True)
其中,predictions是list,结构在surprise库里面是[uid,iid,true_r,est_r,details]格式的,verbose=True会输出数值
调用
accuracy.fcp(predictions)
自己写

其实这个评测指标没有看懂它的用途是什么?之后看懂了再来补充

猜你喜欢

转载自blog.csdn.net/qiqi123i/article/details/87992348