概述

Surprise 是一个用于构建和分析处理显式评分数据的推荐系统的 Python scikit 工具包。

Surprise 的设计理念如下

名称 SurPRISE(大致意思是 :) )代表着 Simple Python RecommendatIon System Engine(简单的 Python 推荐系统引擎)。

请注意,Surprise 不支持隐式评分或基于内容的信息。

入门示例

这是一个简单示例,展示如何(下载或)加载数据集,将其分割用于五折交叉验证,并计算 SVD 算法的 MAE 和 RMSE。

from surprise import SVD
from surprise import Dataset
from surprise.model_selection import cross_validate

# Load the movielens-100k dataset (download it if needed).
data = Dataset.load_builtin('ml-100k')

# Use the famous SVD algorithm.
algo = SVD()

# Run 5-fold cross-validation and print results.
cross_validate(algo, data, measures=['RMSE', 'MAE'], cv=5, verbose=True)

输出:

Evaluating RMSE, MAE of algorithm SVD on 5 split(s).

                  Fold 1  Fold 2  Fold 3  Fold 4  Fold 5  Mean    Std     
RMSE (testset)    0.9367  0.9355  0.9378  0.9377  0.9300  0.9355  0.0029  
MAE (testset)     0.7387  0.7371  0.7393  0.7397  0.7325  0.7375  0.0026  
Fit time          0.62    0.63    0.63    0.65    0.63    0.63    0.01    
Test time         0.11    0.11    0.14    0.14    0.14    0.13    0.02    

Surprise 功能远不止于此(例如,GridSearchCV)!您可以在文档中找到更多使用示例

基准测试

下表展示了各种算法(使用默认参数)在五折交叉验证过程中的平均 RMSE、MAE 和总执行时间。使用的数据集为 Movielens 100k 和 1M 数据集。所有算法使用相同的交叉验证折叠。所有实验均在配备 Intel i5 11代 2.60GHz 处理器的笔记本电脑上运行。生成这些表格的代码可在基准测试示例中找到。

Movielens 100k RMSE MAE 时间
SVD 0.934 0.737 0:00:06
SVD++ (cache_ratings=False) 0.919 0.721 0:01:39
SVD++ (cache_ratings=True) 0.919 0.721 0:01:22
NMF 0.963 0.758 0:00:06
Slope One 0.946 0.743 0:00:09
k-NN 0.98 0.774 0:00:08
Centered k-NN 0.951 0.749 0:00:09
k-NN Baseline 0.931 0.733 0:00:13
Co-Clustering 0.963 0.753 0:00:06
Baseline 0.944 0.748 0:00:02
Random 1.518 1.219 0:00:01
Movielens 1M RMSE MAE 时间
SVD 0.873 0.686 0:01:07
SVD++ (cache_ratings=False) 0.862 0.672 0:41:06
SVD++ (cache_ratings=True) 0.862 0.672 0:34:55
NMF 0.916 0.723 0:01:39
Slope One 0.907 0.715 0:02:31
k-NN 0.923 0.727 0:05:27
Centered k-NN 0.929 0.738 0:05:43
k-NN Baseline 0.895 0.706 0:05:55
Co-Clustering 0.915 0.717 0:00:31
Baseline 0.909 0.719 0:00:19
Random 1.504 1.206 0:00:19

安装

使用 pip(需要安装 numpy 和 C 编译器。Windows 用户可能更倾向于使用 conda)

$ pip install numpy
$ pip install scikit-surprise

使用 conda

$ conda install -c conda-forge scikit-surprise

要获取最新版本,您也可以克隆仓库并构建源代码(首先需要 Cythonnumpy

$ pip install numpy cython
$ git clone https://github.com/NicolasHug/surprise.git
$ cd surprise
$ python setup.py install

许可证与引用

本项目采用 BSD 3-Clause 许可证授权,因此几乎可以用于任何用途,包括商业应用。

我很想知道 Surprise 对您有什么帮助。请随时创建 Issue 并描述您的使用方式!

如果您在研究中使用 Surprise,请务必引用该论文

@article{Hug2020,
  doi = {10.21105/joss.02174},
  url = {https://doi.org/10.21105/joss.02174},
  year = {2020},
  publisher = {The Open Journal},
  volume = {5},
  number = {52},
  pages = {2174},
  author = {Nicolas Hug},
  title = {Surprise: A Python library for recommender systems},
  journal = {Journal of Open Source Software}
}

贡献者

以下人员为 Surprise 做出了贡献

ashtou, Abhishek Bhatia, bobbyinfj, caoyi, Chieh-Han Chen, Raphael-Dayan, Олег Демиденко, Charles-Emmanuel Dias, dmamylin, Lauriane Ducasse, Marc Feger, franckjay, Lukas Galke, Tim Gates, Pierre-François Gimenez, Zachary Glassman, Jeff Hale, Nicolas Hug, Janniks, jyesawtellrickson, Doruk Kilitcioglu, Ravi Raju Krishna, lapidshay, Hengji Liu, Ravi Makhija, Maher Malaeb, Manoj K, James McNeilis, Naturale0, nju-luke, Pierre-Louis Pécheux, Jay Qi, Lucas Rebscher, Craig Rodrigues, Skywhat, Hercules Smith, David Stevens, Vesna Tanko, TrWestdoor, Victor Wang, Mike Lee Williams, Jay Wong, Chenchen Xu, YaoZh1918.

非常感谢 :) !

开发状态

自 1.1.0 版本(2019年9月)起,我将只负责维护该软件包,提供错误修复,有时可能会进行性能改进。目前我没有太多时间投入,因此无法考虑新功能。

关于 Surprise 的 Bug、问题或疑问,请避免给我发送电子邮件;我可能无法回复。请改为使用 GitHub 项目页面,以便其他人也能从中受益。