Implicit feedback-based recommender systems, packed for practitioners.
Project description
irspack - Implicit recommender systems for practitioners
irspack is a Python package for recommender systems based on implicit feedback, designed to be used by practitioners.
Some of its features include:
- Efficient parameter tuning enabled by C++/Eigen implementations of core recommender algorithms and optuna.
- In particular, if an early stopping scheme is available, optuna can prune out unpromising trial based on the intermediate validation scores.
- Various utility functions, including
- ID/index mapping utilities
- Fast, multithreaded argsort for batch recommendation retrieval
- Efficient and configurable evaluation of recommender system performance
Installation & Optional Dependencies
In most cases, you can install the pre-build binaries via
pip install irspack
The binaries have been compiled to use AVX instruction. If you want to use AVX2/AVX512 or your environment does not support AVX (like Rosetta 2 on Apple M1), install it from source like
CFLAGS="-march=native" pip install git+https://github.com/tohtsky/irspack.git
In that case, you must have a decent version of C++ compiler (with C++11 support). If it doesn't work, feel free to make an issue!
Optional Dependencies
I have also prepared a wrapper class (BPRFMRecommender
) to train/optimize BPR/warp loss Matrix factorization implemented in lightfm. To use it you have to install lightfm
separately, e.g. by
pip install lightfm
If you want to use Mult-VAE, you'll need the following additional (pip-installable) packages:
- jax
- jaxlib
- If you want to use GPU, follow the installation guide https://github.com/google/jax#installation
- dm-haiku
- optax
Basic Usage
Step 1. Train a recommender
To begin with, we represent the user/item interaction as a scipy.sparse matrix. Then we can feed it into recommender classes:
import numpy as np
import scipy.sparse as sps
from irspack import IALSRecommender, df_to_sparse
from irspack.dataset import MovieLens100KDataManager
df = MovieLens100KDataManager().read_interaction()
# Convert pandas.Dataframe into scipy's sparse matrix.
# The i'th row of `X_interaction` corresponds to `unique_user_id[i]`
# and j'th column of `X_interaction` corresponds to `unique_movie_id[j]`.
X_interaction, unique_user_id, unique_movie_id = df_to_sparse(
df, 'userId', 'movieId'
)
recommender = IALSRecommender(X_interaction)
recommender.learn()
# for user 0 (whose userId is unique_user_id[0]),
# compute the masked score (i.e., already seen items have the score of negative infinity)
# of items.
recommender.get_score_remove_seen([0])
Step 2. Evaluation on a validation set
To evaluate the performance of a recommenderm we have to split the dataset to train and validation sets:
from irspack.split import rowwise_train_test_split
from irspack.evaluation import Evaluator
# Random split
X_train, X_val = rowwise_train_test_split(
X_interaction, test_ratio=0.2, random_state=0
)
evaluator = Evaluator(ground_truth=X_val)
recommender = IALSRecommender(X_train)
recommender.learn()
evaluator.get_score(recommender)
This will print something like
{
'appeared_item': 435.0,
'entropy': 5.160409123151053,
'gini_index': 0.9198367595008214,
'hit': 0.40084835630965004,
'map': 0.013890322881619916,
'n_items': 1682.0,
'ndcg': 0.07867240014767263,
'precision': 0.06797454931071051,
'recall': 0.03327028758587522,
'total_user': 943.0,
'valid_user': 943.0
}
Step 3. Hyperparameter optimization
Now that we can evaluate the recommenders' performance against the validation set, we can use optuna-backed hyperparameter optimization.
best_params, trial_dfs = IALSRecommender.tune(X_train, evaluator, n_trials=20)
# maximal ndcg around 0.43 ~ 0.45
trial_dfs["ndcg@10"].max()
Of course, we have to hold-out another interaction set for test, and measure the performance of tuned recommender against the test set.
See examples/
for more complete examples.
TODOs
- more benchmark dataset
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file irspack-0.3.0.tar.gz
.
File metadata
- Download URL: irspack-0.3.0.tar.gz
- Upload date:
- Size: 143.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac2ed90af66562f16257907068ed79e1ddf437543b31da04dfb7d68781d1f639 |
|
MD5 | 09ec3a9ad40949240f6ea0ec8647d1bc |
|
BLAKE2b-256 | 7a6ac14ba45693afbe773c84957b6acf2f413e17c73e5035f2af826c04fb33d4 |
File details
Details for the file irspack-0.3.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 567.6 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a1118ef9acf60606561a08753485a4d010373555a8d6fabb57fac5ee7ae7f8c |
|
MD5 | 2fc2379484af954a17536096b7568465 |
|
BLAKE2b-256 | 3375f2b52d97a65fc15aa70a305368271dd1ba642ed99ca99e18ff907bbd0765 |
File details
Details for the file irspack-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 853.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1629298efae9c0065cf8270ae9c5f0c7dc32c25d0954a09f982133891987c1c1 |
|
MD5 | c6fdd782dec949915e8044f61417b9df |
|
BLAKE2b-256 | 09de630d051c1155e644d123a51c847893cc1848b88efaab87be1f2016c8f2ea |
File details
Details for the file irspack-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 796.1 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b36207dc62c006a18216a342832e1d5466ae35c67f672b7a705e82004217ea60 |
|
MD5 | be5bb6de57162bb5b6a43c3f1184f766 |
|
BLAKE2b-256 | 2128658ecf13f794757e65521fbda7a2b7897dacb0dec3b0f79bca31ab76bddf |
File details
Details for the file irspack-0.3.0-cp310-cp310-macosx_10_9_universal2.whl
.
File metadata
- Download URL: irspack-0.3.0-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 011d8a12499b7921a16b4950089387bef2cc6f1da1d6e3ff0e24715d9a37f3c4 |
|
MD5 | 7b5a22435b472cb173dd8b9330fe01ca |
|
BLAKE2b-256 | 30022bc163f41d04657167c3879d9cda4604b5717ce70d0c837a9a3ef45e3aa4 |
File details
Details for the file irspack-0.3.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 562.4 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cddf0aaaa91fafe2bab77ffbd44ad4a93203646018aa1f2ba61acf0d3c191527 |
|
MD5 | 81bd0ae795d05802d436ab537f9f64f2 |
|
BLAKE2b-256 | 15a632cbc2a62bf2a17ced14270e1948c9f131671df5b549c8c07f8915539f37 |
File details
Details for the file irspack-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 854.1 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27559a1a0b9d1386bb9f83185ec95b68027600fbb351303c22b5c10471653c44 |
|
MD5 | 4a1142774fe95b2f1abe225a0ba60363 |
|
BLAKE2b-256 | ca5eab756558fdb42fa78008f081ad46d37d648e4b31d4cd391f9e9f70a604df |
File details
Details for the file irspack-0.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 797.4 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 369ad701c70a1663bccb85c355cf1c3c763afdad8bcffec8171ca1a7de8e19e6 |
|
MD5 | 6db2a99c8d0ab850bad3639009cd845b |
|
BLAKE2b-256 | 7a0ccd2c0b8983d4af9157609480f68719dd9b4013825266cc1b721431022f6f |
File details
Details for the file irspack-0.3.0-cp39-cp39-macosx_10_9_universal2.whl
.
File metadata
- Download URL: irspack-0.3.0-cp39-cp39-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a27fe0cc9540398ede38472340966e2374597239d4074dd6dcddb1a9784325b |
|
MD5 | d50a4d2a680983538202ddd4e4974ae7 |
|
BLAKE2b-256 | d46b7891bf14f36b46958bd219f61b698f3f6457310ebaab86ed335e24104096 |
File details
Details for the file irspack-0.3.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 567.4 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27c54cce15e26e161e84dc73754cb16b45d5be6507f5e664f6419f63e946178c |
|
MD5 | 38dada237ebf202bbef985ae53dc0d49 |
|
BLAKE2b-256 | 510d68057a175bbec600428c8d32bccdcaea06025427687c38ea8b36db30ad0d |
File details
Details for the file irspack-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 852.4 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ad0b7002c53b43c64eb58ffad107b6e3f0fc462a587852d345c44f73622d5b1 |
|
MD5 | 84e9c0d524f3b806ceb6b94d2d78ad78 |
|
BLAKE2b-256 | 0414f496538111be7a8c9ef63d2dcaf2657877892e150ea0e6671ad95e6fe346 |
File details
Details for the file irspack-0.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 796.0 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbccca9681f84b0d1a9fbe6543f7b7863f1eeee0695709d50bf83b8df202f345 |
|
MD5 | 136b01a64ada73e3a72d06a966cf835a |
|
BLAKE2b-256 | d897541f0f23bd23c459be7450f93cc1396481f6b62c763028a773785f352f36 |
File details
Details for the file irspack-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 633.4 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54338caaf8084abba01a920c194de97176583708277de9ec5db1c77161a0c18f |
|
MD5 | aab7bd5b26d87034a1bb88d953b4ef64 |
|
BLAKE2b-256 | 4993beae5987382fcf3bc3b1dcd0f8819ab254cb7ae5d597dd1af3140efb798d |
File details
Details for the file irspack-0.3.0-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 568.7 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f849d1213438569b4c0573f3f1876098570043297ee669780e3bea650faaeda8 |
|
MD5 | ced292f9b42fc312f7f73e8adadf7dc2 |
|
BLAKE2b-256 | f5e5be3f38e70ff4337057003b106bd222e0921574f822d69965d727fb93aa98 |
File details
Details for the file irspack-0.3.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 815.1 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cee087b443854b17144138640cf44151b3c37973b64c8bbcc5f55dbd6d7e367 |
|
MD5 | 045782d3f0f4e8bda173e5e843efa4fd |
|
BLAKE2b-256 | 2f8fd2daea60584c6a6db45e0e5fb338f1b7299cce1c51e03ea1ee366be6a0e6 |
File details
Details for the file irspack-0.3.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 840.2 kB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f620dd71d8f1e491f043505899c85df1ff31638370405cc17412eabb2b44e9b |
|
MD5 | 4f2d9de80527a9feb1f3f6329cb87aff |
|
BLAKE2b-256 | c269a04c148d678f15ac698facfe306cf666771f09aee12d42972cf7213adfcb |
File details
Details for the file irspack-0.3.0-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: irspack-0.3.0-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 626.6 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd25881d8f06b50f1ed9a37b0b64ee61b437436b0e445710a37c6d6befa2689e |
|
MD5 | 4091c6f28d86c8add417fd97b01f0991 |
|
BLAKE2b-256 | fe1f186459d11ebda3337fa2bdb5101aa1fe8bba18017d94c69dfeb6af1e83b8 |