# Top 3 Python Packages to Learn the Recommendation System

By [wang0766](https://paragraph.com/@wang0766) · 2021-12-12

---

从这些包中学习以提高您的推荐系统知识
------------------

![Cornellius Yudha Wijaya](https://storage.googleapis.com/papyrus_images/9d462cfd1140a3c8a65bb8de451bd133ddae993e0bb13303379c6aa392e36103.jpg)

Cornellius Yudha Wijaya

![](https://storage.googleapis.com/papyrus_images/67cb26cdd620a968c5358b4c1ece9be5a7e0b54618b6793772e54858cafff294.jpg)

照片由[维多利亚诺·伊斯基耶多](https://unsplash.com/@victoriano?utm_source=medium&utm_medium=referral)在[Unsplash](https://unsplash.com/?utm_source=medium&utm_medium=referral)

推荐系统是一个数据科学问题，它根据历史数据预测用户或客户想要什么。推荐系统有两种常见的工作方式——协同过滤和基于内容的过滤。

上面的条款你觉得熟悉吗？可能是可能不是。无论如何，本文旨在更好地理解使用这三大 Python 包的推荐系统。这些包是什么？让我们开始吧！

1\. 惊喜
------

[Surprise](https://github.com/NicolasHug/Surprise) is an open-source Python package for building a recommendation system based on the rating data. The name SurPRISE is an abbreviation for the _Simple Python RecommendatIon System Engine_. The package provides all the necessary tools for building the recommendation system — from loading the dataset, choosing the prediction algorithm, and evaluating the model.

Let’s install the package to learn more about the recommendation system.

    pip install scikit-surprise
    

After installing the package, let’s try to build a recommendation system based on the tutorial package. We did this to see if the package had been properly installed or not.

    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)
    

![](https://storage.googleapis.com/papyrus_images/25ae846bf60485f6cb8572313b703c948364f3cbf7a570d772e5b9c4c8335fac.png)

Image by Author

If you can see the output above, you are good to go. The code above analyzes the dataset by rating, and using the SVD algorithm; we create the recommendation system. The metrics we evaluated are RMSE and MAE with 5-fold as an evaluation method.

If we want to understand further how the algorithm and evaluation work, we could visit the [Surprise documentation](https://surprise.readthedocs.io/en/stable/index.html). The developer has stated that they strongly emphasized the documentation to explain every detail of the algorithm. That is why we would explore documentation for our material learning.

![](https://storage.googleapis.com/papyrus_images/3033727d0b365357eb2cb2909ce5197dd4876e9661299629bb34af90560a7424.gif)

GIF by Author

If we look at the Getting Started part, the documentation is full of learning material on developing machine learning prediction for recommendation systems and evaluating it.

If we look at the prediction algorithm section, we will get a more detailed part about the estimation using baseline estimates and similarity measures. This part is pretty well written and lets you understand the basic algorithm used in the recommendation system.

![](https://storage.googleapis.com/papyrus_images/7f9cc48a74809e85f6f82147af66d3646beec865dc3d7c3391bb42c20868c9c9.png)

Image by Author

The documentation also gives you an excellent selection for learning material; I suggest you could start from the following section to learn more about the model and the evaluation:

*   [prediction\_algorithms package](https://surprise.readthedocs.io/en/stable/prediction_algorithms_package.html)
    
*   [The model\_selection package](https://surprise.readthedocs.io/en/stable/model_selection.html)
    
*   [similarities module](https://surprise.readthedocs.io/en/stable/similarities.html#)
    
*   [accuracy module](https://surprise.readthedocs.io/en/stable/accuracy.html)
    
*   [dataset module](https://surprise.readthedocs.io/en/stable/dataset.html)
    

What I love from this documentation is all the calculations and equitation written in detail so you can understand what happened under the hood. For example, the calculation is written clearly in the image below for the cosine similarities.

![](https://storage.googleapis.com/papyrus_images/5bf8fa2457f589db7ac6b63c92fb6b3dab5c048524a9e4aa12f9b44253bdefc3.png)

Image by Author

2\. TensorFlow Recommenders
---------------------------

The TensorFlow framework contains a library to build the recommendation system called [TensorFlow Recommenders](https://github.com/tensorflow/recommenders). Like the other package, the TensorFlow Recommenders contains dataset examples, recommender algorithms, model evaluations, and deployment.

To Install the package, you need to run the following code.

    pip install tensorflow-recommenders
    

TensorFlow Recommenders would allow us to build a recommendation system based only on the TensorFlow framework. However, the documentation is complete for beginners as it is written for beginners and professionals alike. Let’s take a look at the [documentation](https://www.tensorflow.org/recommenders) page for learning.

![](https://storage.googleapis.com/papyrus_images/4ce5f3f149621aee2f6a45eb2fc8ded7c73df5dce753fd01a5741ab0e419c950.gif)

GIF by Author

The documentation is structured from how you load the data, select the algorithm, and evaluate it.

Not only does the documentation contain the how-to-work for the beginner, but it also gives you tips on related content such as Feature Preprocessing.

![](https://storage.googleapis.com/papyrus_images/45639ec1e8ce1b031f1b366ab63745a61cf64ae09f1cc38840ca35bd7b44909e.png)

Image by Author

If you want to look at a more advanced use case, you could check out the Documentation for Intermediate cases. It shows you content such as Multitask recommenders, Cross networks, etc.

![](https://storage.googleapis.com/papyrus_images/da1a0265b616d08f76a8d7aed78ff4df5ae2775799460db1e9e04d2fb230741d.png)

Image by Author

If you want to have the source code or contribute to the open-source, you could visit the [GitHub page](https://github.com/tensorflow/recommenders).

3\. Recmetrics
--------------

Learning about the recommendation system algorithm would not be complete without the evaluation metrics. The previous article I mentioned has taught us some basic recommendation evaluation metrics, but a Python package focuses on the metrics — [Recmetrics](https://github.com/statisticianinstilettos/recmetrics).

To install the package, you only need to run the following code.

该包包含许多推荐系统的评估指标，例如：

*   长尾图
    
*   覆盖范围
    
*   新奇
    
*   个性化
    
*   列表内相似度
    

还有很多。[GitHub 页面](https://github.com/statisticianinstilettos/recmetrics)上提供了对指标的所有解释。

![](https://storage.googleapis.com/papyrus_images/d23b3ec2958af2a7f7b145970a1a6d10275563177c3370bcb781b0cb4cdc8a9f.gif)

作者的 GIF

如果要使用示例数据集探索包，可以探索包中提供的[示例笔记本](https://github.com/statisticianinstilettos/recmetrics/blob/master/example.ipynb)。

结论
--

推荐系统是一个数据科学问题，它根据历史数据预测用户或客户想要什么。学习推荐系统可以更好地与 Python Package 一起陪伴你的学习。我推荐的包是：

1.  惊喜
    
2.  TensorFlow 推荐
    
3.  计量学
    

我希望它有帮助！

在我的\*\*[LinkedIn](https://www.linkedin.com/in/cornellius-yudha-wijaya/)\*\* \*\* \*\* 或\*\*[Twitter](https://twitter.com/CornelliusYW)\*\*上访问我。

> \*如果您喜欢我的内容并希望获得有关数据或作为数据科学家的日常生活的更深入的知识，请考虑**_在此处_**订阅我的 \***_时事通讯。_**

> _如果您不是以 Medium 会员身份订阅的，请考虑通过_[_我的推荐_](https://cornelliusyudhawijaya.medium.com/membership)_订阅_。

---

*Originally published on [wang0766](https://paragraph.com/@wang0766/top-3-python-packages-to-learn-the-recommendation-system)*
