scikit-learn - 如何评估基于内容的推荐系统
问题描述
我创建了一个基于内容的推荐器,它将根据它们的描述推荐 10 个类似的产品。现在我想评估它的准确性和效率。到目前为止,当我想评估系统的准确性时,一切都运行良好。我在 Google 上找到的一些公式只是根据评分值评估准确性(比较预测评分和实际评分,如 RMSE)。我没有将相似度分数更改为评分(从 1 到 5 的等级),所以我无法应用任何公式。
我使用了余弦相似度和 tfidf 矢量化器。当我对交叉验证使用意外时,出现“无原始评级”错误。我需要一些参数来评估推荐系统的准确性和效率。
tfidf 的代码:
from sklearn.feature_extraction.text import TfidfVectorizer
##remove stop words
tfidf=TfidfVectorizer(stop_words='english')
###replace non with empty string NaN
df1['product_desc']=df1['product_desc'].fillna('')
##construct tfidf
tfidf_matrix=tfidf.fit_transform(df1['product_desc'])
tfidf_matrix.shape
和余弦相似度
###cosine similarity
from sklearn.metrics.pairwise import linear_kernel
cosine_sim=linear_kernel(tfidf_matrix, tfidf_matrix)
###create reverse map
indices=pd.Series(df1.index,index=df1['product_name']).drop_duplicates()
def get_recommendation(title, cosine_sim=cosine_sim):
idx=indices[title]
sim_score=list(enumerate(cosine_sim[idx]))
sim_score=sorted(sim_score, key=lambda x:x[1], reverse=True)
sim_score=sim_score[1:2]
p_indices=[i[0] for i in sim_score]
name=df1['product_name'].iloc[p_indices]
return idx
所以需要一些公式来评估基于内容的推荐器
解决方案
推荐阅读
- python - 列表理解/生成器表达式中的“x in y”的对立面是什么?
- ag-grid - ag-Grid 中 cellStyle 和 rowStyle 的样式冲突
- python - PyInstaller:无法为未注册的加载程序类型执行此操作
- laravel - Laravel 碳日期添加 7 分钟
- php - PHP Spreadsheet / Laravel Excel - CSV 中的日期格式在编辑后转换为用户本地格式
- mule - 访问变量中的属性 json (flowVars) Mulesoft
- wcf - 如何手动创建 wcf 服务故障异常?
- java - 无法解析查询 - 在 graphql.GraphQL.execute()
- javascript - iOS 移动浏览器上的切换选项卡无法通过 href 目标甚至 window.open 窗口焦点工作
- bash - 多个whois查询