MobileTeleSystems / RecTools

RecTools - library to build Recommendation Systems easier and faster than ever before
Apache License 2.0
287 stars 37 forks source link
deep-learning machine-learning personalization recomendations recommendation-algorithms recommendation-engine recommendation-system recommender-system recsys

RecTools

Python versions PyPI Docs

License Coverage Tests

Contributors Downloads Telegram

Documentation | Examples | Tutorials | Contributing | Releases | Developers Board

RecTools is an easy-to-use Python library which makes the process of building recommendation systems easier, faster and more structured than ever before. It includes built-in toolkits for data processing and metrics calculation, a variety of recommender models, some wrappers for already existing implementations of popular algorithms and model selection framework. The aim is to collect ready-to-use solutions and best practices in one place to make processes of creating your first MVP and deploying model to production as fast and easy as possible.

Get started

Prepare data with

wget https://files.grouplens.org/datasets/movielens/ml-1m.zip
unzip ml-1m.zip
import pandas as pd
from implicit.nearest_neighbours import TFIDFRecommender

from rectools import Columns
from rectools.dataset import Dataset
from rectools.models import ImplicitItemKNNWrapperModel

# Read the data
ratings = pd.read_csv(
    "ml-1m/ratings.dat", 
    sep="::",
    engine="python",  # Because of 2-chars separators
    header=None,
    names=[Columns.User, Columns.Item, Columns.Weight, Columns.Datetime],
)

# Create dataset
dataset = Dataset.construct(ratings)

# Fit model
model = ImplicitItemKNNWrapperModel(TFIDFRecommender(K=10))
model.fit(dataset)

# Make recommendations
recos = model.recommend(
    users=ratings[Columns.User].unique(),
    dataset=dataset,
    k=10,
    filter_viewed=True,
)

Installation

RecTools is on PyPI, so you can use pip to install it.

pip install rectools

The default version doesn't contain all the dependencies, because some of them are needed only for specific functionality. Available user extensions are the following:

Install extension:

pip install rectools[extension-name]

Install all extensions:

pip install rectools[all]

Recommender Models

The table below lists recommender models that are available in RecTools.
See recommender baselines extended tutorial for deep dive into theory & practice of our supported models.

Model Type Description (🎏 for user/item features, πŸ”† for warm inference, ❄️ for cold inference support) Tutorials & Benchmarks
implicit ALS Wrapper Matrix Factorization rectools.models.ImplicitALSWrapperModel - Alternating Least Squares Matrix Factorizattion algorithm for implicit feedback.
🎏
πŸ“™ Theory & Practice
πŸš€ 50% boost to metrics with user & item features
implicit ItemKNN Wrapper Nearest Neighbours rectools.models.ImplicitItemKNNWrapperModel - Algorithm that calculates item-item similarity matrix using distances between item vectors in user-item interactions matrix πŸ“™ Theory & Practice
LightFM Wrapper Matrix Factorization rectools.models.LightFMWrapperModel - Hybrid matrix factorization algorithm which utilises user and item features and supports a variety of losses.
🎏 πŸ”† ❄️
πŸ“™ Theory & Practice
πŸš€ 10-25 times faster inference with RecTools
EASE Linear Autoencoder rectools.models.EASEModel - Embarassingly Shallow Autoencoders implementation that explicitly calculates dense item-item similarity matrix πŸ“™ Theory & Practice
PureSVD Matrix Factorization rectools.models.PureSVDModel - Truncated Singular Value Decomposition of user-item interactions matrix πŸ“™ Theory & Practice
DSSM Neural Network rectools.models.DSSMModel - Two-tower Neural model that learns user and item embeddings utilising their explicit features and learning on triplet loss.
🎏 πŸ”†
-
Popular Heuristic rectools.models.PopularModel - Classic baseline which computes popularity of items and also accepts params like time window and type of popularity computation.
❄️
-
Popular in Category Heuristic rectools.models.PopularInCategoryModel - Model that computes poularity within category and applies mixing strategy to increase Diversity.
❄️
-
Random Heuristic rectools.models.RandomModel - Simple random algorithm useful to benchmark Novelty, Coverage, etc.
❄️
-

Extended validation tools

DebiasConfig for debiased metrics calculation

User guide | Documentation

VisualApp for model recommendations comparison

Example | Demo | Documentation

MetricsApp for metrics trade-off analysis

Example | Documentation

Contribution

Contributing guide

To install all requirements

For autoformatting run

make format

For linters check run

make lint

For tests run

make test

For coverage run

make coverage

To remove virtual environment run

make clean

RecTools Team

Previous contributors: Ildar Safilo [ex-Maintainer], Daniil Potapov [ex-Maintainer], Igor Belkov, Artem Senin, Mikhail Khasykov, Julia Karamnova, Maxim Lukin, Yuri Ulianov, Egor Kratkov, Azat Sibagatulin