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

在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)
自己写

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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值