topk推荐系统的评价指标
时间: 2023-11-02 18:05:28 浏览: 491
topk推荐系统的评价指标包括以下几个方面:
1. Precision@k:表示在前k个推荐结果中,有多少个是用户真正感兴趣的,即推荐的物品中用户实际点击或购买的物品占比。
2. Recall@k:表示在所有用户感兴趣的物品中,有多少个被推荐出来了,即推荐列表中实际被用户点击或购买的物品占比。
3. Hit Rate@k:表示在前k个推荐结果中,是否有用户实际点击或购买的物品,即推荐列表中有多少个被用户真正关注。
4. Coverage@k:表示在所有用户感兴趣的物品中,有多少个被推荐出来了,即推荐列表中不同物品的覆盖率。
5. Mean Reciprocal Rank(MRR):表示推荐列表中第一个被点击或购买的物品出现的位置的倒数的平均值。
6. Normalized Discounted Cumulative Gain(NDCG):表示推荐列表的排序质量,将推荐列表中每个物品的相关性打分,计算出排名越靠前的物品所占的得分加权平均值。
7. Average Precision(AP):表示在所有的推荐列表中,每个物品的平均精度,即推荐的物品列表中每个物品的精度加权平均值。
这些指标可以综合评估推荐系统在不同方面的性能,如精度、召回率、覆盖率、排序质量等。
相关问题
使用是 Python Scikit 系列中的推荐系统库 Surprise (Simple Python Recommendation System Engine) 1进行个性化推荐,要求如下: (a) 数据选用 Movielens 电影评分数据集 “ml-100k”, 采用库中的 train_test_split 函数以 4:1 的 比例划分训练集和测试集; (b) 推荐算法分别选择 UCF 和 ICF(参数设置:cosine 相似度,最大相似邻居数量为 50,最小相似 邻居数量为 10); (c) 评价指标采用 RMSE 和 MAE, 同时输出测试集中每一个用户 Top-5 的电影推荐列表。
好的,这是一个关于使用 Surprise 库进行个性化推荐的问题。下面是我对您的问题的回答:
首先,我们需要下载并导入 Surprise 库,以及加载 Movielens 数据集。这可以通过以下代码完成:
```python
!pip install surprise
from surprise import Dataset
from surprise import Reader
# 加载 Movielens 数据集
data = Dataset.load_builtin('ml-100k')
# 按照指定方式读取数据
reader = Reader(line_format='user item rating timestamp', sep='\t')
# 加载数据集,并划分为训练集和测试集
trainset, testset = train_test_split(data, test_size=0.2, random_state=42)
```
接下来,我们需要选择 UCF 和 ICF 算法,并设置参数。这可以通过以下代码完成:
```python
from surprise import KNNWithMeans
from surprise import accuracy
# 使用 UCF 算法
sim_options = {'name': 'cosine', 'user_based': True}
algo_ucf = KNNWithMeans(k=50, min_k=10, sim_options=sim_options)
# 使用 ICF 算法
sim_options = {'name': 'cosine', 'user_based': False}
algo_icf = KNNWithMeans(k=50, min_k=10, sim_options=sim_options)
```
然后,我们需要使用训练集来训练 UCF 和 ICF 算法,并在测试集上进行评估。这可以通过以下代码完成:
```python
# 训练 UCF 算法
algo_ucf.fit(trainset)
# 在测试集上评估 UCF 算法
predictions_ucf = algo_ucf.test(testset)
# 训练 ICF 算法
algo_icf.fit(trainset)
# 在测试集上评估 ICF 算法
predictions_icf = algo_icf.test(testset)
# 计算 RMSE 和 MAE 指标
rmse_ucf = accuracy.rmse(predictions_ucf)
mae_ucf = accuracy.mae(predictions_ucf)
rmse_icf = accuracy.rmse(predictions_icf)
mae_icf = accuracy.mae(predictions_icf)
```
最后,我们需要输出测试集中每一个用户 Top-5 的电影推荐列表。这可以通过以下代码完成:
```python
from collections import defaultdict
# 为每个用户获取 Top-5 推荐列表
def get_top_n(predictions, n=5):
top_n = defaultdict(list)
for uid, iid, true_r, est, _ in predictions:
top_n[uid].append((iid, est))
for uid, user_ratings in top_n.items():
user_ratings.sort(key=lambda x: x[1], reverse=True)
top_n[uid] = user_ratings[:n]
return top_n
# 获取 UCF 推荐列表
top_n_ucf = get_top_n(predictions_ucf)
# 获取 ICF 推荐列表
top_n_icf = get_top_n(predictions_icf)
# 输出每个用户的 Top-5 推荐列表
for uid, user_ratings in top_n_ucf.items():
print(uid, [iid for (iid, _) in user_ratings])
for uid, user_ratings in top_n_icf.items():
print(uid, [iid for (iid, _) in user_ratings])
```
这样,就可以完成个性化推荐的任务,并输出评价指标和测试集中每一个用户 Top-5 的电影推荐列表。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)