irspack
irspack is a Python package to train, evaluate, and optimize recommender systems based on implicit feedback.
There are already great packages for this purpose like
- implicit
- daisyRec
- RecSys2019_DeepLearning_Evaluation (which has influenced this project the most)
However, I decided to implement my own one to
- Use optuna for more efficient parameter search. In particular, if an early stopping scheme is available, optuna can prune unpromising trial based on the intermediate validation score, which drastically reduces overall running time for tuning.
- Use multi-threaded implementations of the number of algorithms (KNN and IALS) in C++.
- Deal with user cold-start scenarios using "CB2CF" strategy, which I found very convenient in practice.
Installation & Optional Dependencies
There are binaries for Linux, MacOS, and Windows with python>=3.6. You can install them 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, 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).
Optional Dependencies
I have also prepared a wrapper class (BPRFMRecommender) to train and 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 and CB2CF features in cold-start scenarios, 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
We first represent the user/item interaction as a scipy.sparse matrix. Then we can feed it into our Recommender classes:
import numpy as np
import scipy.sparse as sps
from irspack.recommenders import P3alphaRecommender
from irspack.dataset.movielens import MovieLens100KDataManager
df = MovieLens100KDataManager().read_interaction()
unique_user_id, user_index = np.unique(df.userId, return_inverse=True)
unique_movie_id, movie_index = np.unique(df.movieId, return_inverse=True)
X_interaction = sps.csr_matrix(
(np.ones(df.shape[0]), (user_index, movie_index))
)
recommender = P3alphaRecommender(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. Evaluate on a validation set
We have to split the dataset to train and validation sets
from irspack.split import rowwise_train_test_split
from irspack.evaluator import Evaluator
X_train, X_val = rowwise_train_test_split(
X_interaction, test_ratio=0.2, random_seed=0
)
# often, X_val is defined for a subset of users.
# `offset` specifies where the validated user blocks begin.
# In this split, X_val is defined for the same users as X_train,
# so offset = 0
evaluator = Evaluator(ground_truth=X_val, offset=0)
recommender = P3alphaRecommender(X_train)
recommender.learn()
evaluator.get_score(recommender)
This will print something like
{
'appeared_item': 106.0,
'entropy': 3.840445116672292,
'gini_index': 0.9794929280523742,
'hit': 0.8854718981972428,
'map': 0.11283343078231302,
'n_items': 1682.0,
'ndcg': 0.3401244303579389,
'precision': 0.27560975609756017,
'recall': 0.19399215770339678,
'total_user': 943.0,
'valid_user': 943.0
}
Step 3. Optimize the Hyperparameter
Now that we can evaluate the recommenders' performance against the validation set, we can use optuna-backed hyperparameter optimizer.
from irspack.optimizers import P3alphaOptimizer
optimizer = P3alphaOptimizer(X_train, evaluator)
best_params, trial_dfs = optimizer.optimize(n_trials=20)
# maximal ndcg around 0.38 ~ 0.39
trial_dfs.ndcg.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
- complete documentation
- more splitting schemes
- more benchmark dataset
Metadata
Release files for irspack 0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| irspack-0.tar.gz | 126.6 kB | Without provenance | Details for irspack-0.tar.gz |
Built distributions (wheels)
Total release size: 74.0 MB
Release files / irspack-0.tar.gz
| Download URL | irspack-0.tar.gz |
|---|---|
| Size | 126.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e91106498beb914fae944f958fbccac11ef9ba5f4db31cffeba43bb407a95b85
|
|
BLAKE2b-256 checksum How to use checksums |
7b4661037f00661aee03590d7dade620e1cbcd812c966c672f89e6d6a3134ee5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp39-cp39-win_amd64.whl
| Download URL | irspack-0-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 471.6 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e3d4b2d844204f27d60280e04cb8f1f99e882e2eae9a8777b25c14cb321075ae
|
|
BLAKE2b-256 checksum How to use checksums |
a7a51eeaf1ec039c053b07e388788dd3a90db4124254fc3923d77401a716e2af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp39-cp39-win32.whl
| Download URL | irspack-0-cp39-cp39-win32.whl |
|---|---|
| Size | 428.9 kB |
| Tags | CPython 3.9 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
3061c03134f97e4a40c2d2b6559f8c1e8873f64d1a00370f13ea6ead0e067d46
|
|
BLAKE2b-256 checksum How to use checksums |
ce55532fef05363b2e6d436dda50613140cf7a9dff9bdb0d9552b33c9bf0916b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp39-cp39-manylinux2010_x86_64.whl
| Download URL | irspack-0-cp39-cp39-manylinux2010_x86_64.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.9 Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
4138fab3ef571d4a3cb2cb079ebd529937fa12616788ebe7f7351f7c2c0502a0
|
|
BLAKE2b-256 checksum How to use checksums |
9eaa705268649af23e4b0fc7bd7e15ef1793ffbf3718a01d711eca1dbcd92cdd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp39-cp39-manylinux2010_i686.whl
| Download URL | irspack-0-cp39-cp39-manylinux2010_i686.whl |
|---|---|
| Size | 8.3 MB |
| Tags | CPython 3.9 Linux glibc 2.12+ x86-32 |
|
SHA-256 checksum How to use checksums |
d42d1cdd9d94c60080380ef2431c6663fe76e743253afa71917f3b19d58bdb5e
|
|
BLAKE2b-256 checksum How to use checksums |
246c216c25f1c0899bcdc1dd517aebf06721b3a8e6117f01137a9e941b37ab56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp39-cp39-macosx_10_9_x86_64.whl
| Download URL | irspack-0-cp39-cp39-macosx_10_9_x86_64.whl |
|---|---|
| Size | 578.2 kB |
| Tags | CPython 3.9 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
8f143b9126aedf70e794e034eb58fe326e9aa587eb8b208b87e2a3131f1c1473
|
|
BLAKE2b-256 checksum How to use checksums |
3c59a2d59cddd992da2fbe3b0139493d691f930176e9d2f19d82cb3c2135428b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp38-cp38-win_amd64.whl
| Download URL | irspack-0-cp38-cp38-win_amd64.whl |
|---|---|
| Size | 471.1 kB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
86410df5516dc32c37e5b75bde73720d6ce2608ab02bde38c0251ae970a2cfce
|
|
BLAKE2b-256 checksum How to use checksums |
eb3c6901c42123316aa34c717e9adcf253dacde419573508c205048fe282df48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp38-cp38-win32.whl
| Download URL | irspack-0-cp38-cp38-win32.whl |
|---|---|
| Size | 428.4 kB |
| Tags | CPython 3.8 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
0066daa74346f7cf6692aba61c8096f66a18b2062466753c012b7a0dbe677655
|
|
BLAKE2b-256 checksum How to use checksums |
ad14cc04fdbbe7e79162ab217078563bd601b6695ab533c5776ad2e879702143
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp38-cp38-manylinux2010_x86_64.whl
| Download URL | irspack-0-cp38-cp38-manylinux2010_x86_64.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.8 Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
a4c2ffe45a9a54d1900eb16a6f901b9a824b58f29f6d8a3a887711813fb555e2
|
|
BLAKE2b-256 checksum How to use checksums |
520143b6e0af9ad60cac275dd4130b8256b4a779b0d0dfe752f99da51deb8b11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp38-cp38-manylinux2010_i686.whl
| Download URL | irspack-0-cp38-cp38-manylinux2010_i686.whl |
|---|---|
| Size | 8.3 MB |
| Tags | CPython 3.8 Linux glibc 2.12+ x86-32 |
|
SHA-256 checksum How to use checksums |
9d90d8b0141bbe68d0b483d2d41207bcc706b2cb932ef29dfcc78dea08f7215b
|
|
BLAKE2b-256 checksum How to use checksums |
7d75dafde25ee87b86d76f94dd6070e310cb5bc53182a0f8d2efc3cc0a8d4f3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp38-cp38-macosx_10_9_x86_64.whl
| Download URL | irspack-0-cp38-cp38-macosx_10_9_x86_64.whl |
|---|---|
| Size | 578.3 kB |
| Tags | CPython 3.8 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
c1200a4c54811bb8b1a2f8e544920d5f4e3f0aaecddb43144ca0dced92ab7f4a
|
|
BLAKE2b-256 checksum How to use checksums |
a6bec85475c9ab92a2c3da1caf7c77374f02eff1a7334080c5f2bd8d58e16458
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp37-cp37m-win_amd64.whl
| Download URL | irspack-0-cp37-cp37m-win_amd64.whl |
|---|---|
| Size | 474.0 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fd3655080541d90134978124048753ed8141bf76ef8b90e04e43da210311fefc
|
|
BLAKE2b-256 checksum How to use checksums |
87e46b990b8660fd5f4f26a2ec4fa747e39e13566c4afb4c8c5ccb6cb4a97a74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp37-cp37m-win32.whl
| Download URL | irspack-0-cp37-cp37m-win32.whl |
|---|---|
| Size | 431.5 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
b52bb0ca0c592ffab8a4f4fc35036afdc46600c23ef65c02c25e8cd5071d427d
|
|
BLAKE2b-256 checksum How to use checksums |
e1e66d9eeb411e09804202b1e14a35eb674099e31902e33d0eb41b690fe62ee0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp37-cp37m-manylinux2010_x86_64.whl
| Download URL | irspack-0-cp37-cp37m-manylinux2010_x86_64.whl |
|---|---|
| Size | 8.7 MB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
04e890af940e822eaaf73e3480ab8407ce23d5d022fe977d20dadfdf387791c5
|
|
BLAKE2b-256 checksum How to use checksums |
1c526c0b2a78be09cce10f5ca5125336c8724ce681f2ecafdd3b8e1c37a3224e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp37-cp37m-manylinux2010_i686.whl
| Download URL | irspack-0-cp37-cp37m-manylinux2010_i686.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-32 |
|
SHA-256 checksum How to use checksums |
b492a5c856f95e2c723d08d05d267e367ecf094c05f80cb79bf7a8867ef81eec
|
|
BLAKE2b-256 checksum How to use checksums |
a3a2acf67bfe003d9b5bc8c04e67de631c769b526c271f66cfe37ba938b6e1d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp37-cp37m-macosx_10_9_x86_64.whl
| Download URL | irspack-0-cp37-cp37m-macosx_10_9_x86_64.whl |
|---|---|
| Size | 572.7 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
d35bb146e7005857a3878eb3630c417518c1254dabe9330a15f2e4a9525f1476
|
|
BLAKE2b-256 checksum How to use checksums |
92e45051842ac269ad0085cf9e4fdf4b7c25343b442c0cca3a8504dc8e1d7dba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp36-cp36m-win_amd64.whl
| Download URL | irspack-0-cp36-cp36m-win_amd64.whl |
|---|---|
| Size | 474.0 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8b1de8526be9713f04ef78982e79024038486ef8187f578a72f729328971267d
|
|
BLAKE2b-256 checksum How to use checksums |
11ffc1748d5e266c36e986ec0d430bf8fa1096ba6b913cbfb4e81d32c77c0024
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp36-cp36m-win32.whl
| Download URL | irspack-0-cp36-cp36m-win32.whl |
|---|---|
| Size | 431.4 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Windows x86-32 |
|
SHA-256 checksum How to use checksums |
dcd45b85a60ee2e66054932d1b1cf51c15d6259b8c1161ad81fbd9355f55408d
|
|
BLAKE2b-256 checksum How to use checksums |
a7c2ddbf6e75214ae6a4f04f59b412e28d117cb31d6b92e778ed43303c3b7419
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp36-cp36m-manylinux2010_x86_64.whl
| Download URL | irspack-0-cp36-cp36m-manylinux2010_x86_64.whl |
|---|---|
| Size | 8.7 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
5782334f47dfa84ef7341cfd91fc3423dad89175f273fe8e2fe4c70afdc6f01c
|
|
BLAKE2b-256 checksum How to use checksums |
bfcc2f1c779c7ff86e17a11baf7e727c0583fbb07de5629a5aeac3d3570e069d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp36-cp36m-manylinux2010_i686.whl
| Download URL | irspack-0-cp36-cp36m-manylinux2010_i686.whl |
|---|---|
| Size | 8.5 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-32 |
|
SHA-256 checksum How to use checksums |
0088e5a0f754adb13144416b9e8fc3321f586c2099eb385b280c0cec251bfe24
|
|
BLAKE2b-256 checksum How to use checksums |
f93dfe16b3ba6f887cc64a1842a750f1e61d7e8f57c38b2295c220236d7c8aad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Release files / irspack-0-cp36-cp36m-macosx_10_9_x86_64.whl
| Download URL | irspack-0-cp36-cp36m-macosx_10_9_x86_64.whl |
|---|---|
| Size | 572.7 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
6408d1447a61118561dfb16d1aec13c4c47d217caffb86e8cca0018bc55c2862
|
|
BLAKE2b-256 checksum How to use checksums |
55c4ae04ee14df83ca537830b05b9a6c129b7b22926e7e02e382cc3e855d941b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
|
Security for irspack 0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.