Overview

Surprise is a Python scikit for building and analyzing recommender systems that deal with explicit rating data.

Surprise was designed with the following purposes in mind:

The name SurPRISE (roughly ? ) stands for Simple Python RecommendatIon System Engine.

Please note that surprise does not support implicit ratings or content-based information.

Getting started, example

Here is a simple example showing how you can (down)load a dataset, split it for 5-fold cross-validation, and compute the MAE and RMSE of the SVD algorithm.

from surprise import SVDfrom surprise import Datasetfrom 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)

Output:

Evaluating RMSE, MAE of algorithm SVD on 5 split(s).
        Fold 1  Fold 2  Fold 3  Fold 4  Fold 5  Mean    Std

Surprise can do much more (e.g, GridSearchCV)! You’ll find more usage examples in the documentation .

Benchmarks

Here are the average RMSE, MAE and total execution time of various algorithms (with their default parameters) on a 5-fold cross-validation procedure. The datasets are the Movielens 100k and 1M datasets. The folds are the same for all the algorithms. All experiments are run on a notebook with Intel Core i5 7th gen (2.5 GHz) and 8Go RAM. The code for generating these tables can be found in the benchmark example.

Movielens 100k RMSE MAE Time
SVD 0.934 0.737 0:00:11
SVD++ 0.92 0.722 0:09:03
NMF 0.963 0.758 0:00:15
Slope One 0.946 0.743 0:00:08
k-NN 0.98 0.774 0:00:10
Centered k-NN 0.951 0.749 0:00:10
k-NN Baseline 0.931 0.733 0:00:12
Co-Clustering 0.963 0.753 0:00:03
Baseline 0.944 0.748 0:00:01
Random 1.514 1.215 0:00:01
Movielens 1M RMSE MAE Time
SVD 0.873 0.686 0:02:13
SVD++ 0.862 0.673 2:54:19
NMF 0.916 0.724 0:02:31
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

Installation

With pip (you’ll need numpy, and a C compiler. Windows users might prefer using conda):

$ pip install numpy
$ pip install scikit-surprise

With conda:

$ conda install -c conda-forge scikit-surprise

For the latest version, you can also clone the repo and build the source (you’ll first need Cython and numpy):

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

License and reference

This project is licensed under the BSD 3-Clause license, so it can be used for pretty much everything, including commercial applications. Please let us know how Surprise is useful to you!

Please make sure to cite the paper if you use Surprise for your research:

@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}
}

GitHub

https://github.com/NicolasHug/Surprise