首页 > 解决方案 > 如何评估基于内容的推荐系统

问题描述

我创建了一个基于内容的推荐器,它将根据它们的描述推荐 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

所以需要一些公式来评估基于内容的推荐器

标签: scikit-learntf-idfrecommendation-enginetfidfvectorizerrecommender-systems

解决方案


推荐阅读