Implicit feedback-based recommender system pack
Project description
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 wherever possible. Currently, several important algorithms (KNN, iALS, SLIM) and performance evaluators are parallelized using C++ thread.
Installation & Optional Dependencies
There are binaries for Linux, MacOS, and Windows with python>=3.6 with x86 architectures. 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 (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 and CB2CF features in cold-start scenarios, you'll need the following additional (pip-installable) packages:
- scikit-learn
- 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
# 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 = 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@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.2.2.tar.gz
.
File metadata
- Download URL: irspack-0.2.2.tar.gz
- Upload date:
- Size: 139.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e41f8be67f21f88b8b4971b72181c496ffcdda624ea7047b6082e40351dd2d1b |
|
MD5 | 0e4f68fc16b5201fafb7aef3d5916192 |
|
BLAKE2b-256 | 30e0caf9431cc4c86a2fc853da9a065ed4fb7698d2eb3e29ab9d08eecf324434 |
File details
Details for the file irspack-0.2.2-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 563.9 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b6bb5058a70cf69fc4d370ea6099b3c8ea51a1a0127e8742c27615d0106c27f |
|
MD5 | f053a37a35fc9d1a683bea38758483a4 |
|
BLAKE2b-256 | 47b82c4d62c66955f3686e15a94198ee88f261ffc8a4edbf58a874e2651d6f7f |
File details
Details for the file irspack-0.2.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 10.8 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 978bbff6b4949380a2bfba85fb1bccfa999a3f0eaa73ad1d161502f4848157dd |
|
MD5 | 23b92094c32fb0618a257b900a45c832 |
|
BLAKE2b-256 | 50098f1b1ab7d04817a9262f8c359809cd20e0a95e59c68ac986394cc42c3e16 |
File details
Details for the file irspack-0.2.2-cp310-cp310-macosx_10_9_universal2.whl
.
File metadata
- Download URL: irspack-0.2.2-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d1cfeb17f61037b82b43fbd8fad283b86c98aab9fa8d951091dbf81d0ca7b47 |
|
MD5 | bb3e1adfb3da5513ae4a9140c4bb8530 |
|
BLAKE2b-256 | 7d752ba41b1e493a0a29beb947529ab763516a04fcbecd902a6f03325829052f |
File details
Details for the file irspack-0.2.2-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 557.5 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efba6abd67c7b81675a0f6ee714e7dc08e4eb8f33684570e94ebb933578d89fb |
|
MD5 | 504678233e7eb2164c64bd16585dffb9 |
|
BLAKE2b-256 | 61f224d4b13f868b3d34204600635a878ed385ca002d5ac96caf3782d4744156 |
File details
Details for the file irspack-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 10.9 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb7bd95071e6ad912b2f43315af4b7342a8ef9d131c4de0151b3c2e3194f16ce |
|
MD5 | 81ca182cd82209c6c2ed67ec6258115f |
|
BLAKE2b-256 | b1d8a14342c5d6fc9295244aa9458f0d0c0c042013f049b88b096400691453ab |
File details
Details for the file irspack-0.2.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 10.8 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0be9e635606150918ab50391eb18f61ab53da6bf3e4358305290db40495c0fc |
|
MD5 | 1bf64599ef3a42b07600106e70b0a966 |
|
BLAKE2b-256 | db063612a7ef410cb84b295f365997c289dceab9c106e4def84818ef3f34609e |
File details
Details for the file irspack-0.2.2-cp39-cp39-macosx_10_9_universal2.whl
.
File metadata
- Download URL: irspack-0.2.2-cp39-cp39-macosx_10_9_universal2.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0396b5c6e2f013b6ca38c6fbd8fcaabe76fb4db8853e58d04c574f285741e978 |
|
MD5 | 68860d774ca778b26f1a7ae12c9d4ea0 |
|
BLAKE2b-256 | 6cbc0e3c78c4394197495e67ff82747a94d9e4979713dae81ca0a7f202ebcc70 |
File details
Details for the file irspack-0.2.2-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 563.4 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 874fc9a6bfc7d2adb22299af7bc64bc7c99cdf96fb82e6d90e727f0df39741d4 |
|
MD5 | 102c804d24d6a3e75cdc397c6dad1899 |
|
BLAKE2b-256 | 4d5dcf319485ddef5af5d76ba68483e158a9a1527456640037708c707fd47e34 |
File details
Details for the file irspack-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 10.9 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b108a3f87d02c40e95636c557e0d2be694c374970c70c6a322284559df634a6d |
|
MD5 | 62a66facb4478a7f9c579050a0e7b330 |
|
BLAKE2b-256 | 965dd2ee15da62a0b58555da14a84054fb6d01910eac3b36fe93d41552ba552a |
File details
Details for the file irspack-0.2.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 10.8 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 523b6398fc8b3518b2862f1c51d1ad84e7f58a86c9bef28a4dc489c5f8390fe3 |
|
MD5 | 6a1edb49772e85b53d3618625fa4cf94 |
|
BLAKE2b-256 | 43a8cf10e2750f3446fd8284728fa374d9feade7772bafb12cb224a9a70e5be6 |
File details
Details for the file irspack-0.2.2-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 714.1 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01550d6921f94788e999e06c091f3b051afc8bc6e3169b2b903de22454e7a2ec |
|
MD5 | 8a4fe71b95f2ce8c91d1edec6b088f4e |
|
BLAKE2b-256 | d732f0ed6c0b4adea55e7877bc7f76d1deed0714bfb0c03c49e74a05daf0c71f |
File details
Details for the file irspack-0.2.2-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 564.6 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ae04e335623f07c2642351060fdb42e9746353d713eb1fbbf560a1301edd648 |
|
MD5 | ba63cf8a3caa356cfc79f8bb42cae09b |
|
BLAKE2b-256 | ca08d6c6ae66f71ac09da4582cdf29f27debc2bcc3ba390e0fef4c517544e2cc |
File details
Details for the file irspack-0.2.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 11.1 MB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb41bf4371013ec8bc86f9924b4e5e798d277ccde141dbfffe7fd9578e5ce5fc |
|
MD5 | 7a7e1da46b2bc697b9ca36b95ed5526a |
|
BLAKE2b-256 | e3933c0d57319f740602b1bff6753c4e5df1249b1b21f211804e970e78bb61bd |
File details
Details for the file irspack-0.2.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
- Upload date:
- Size: 10.7 MB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dadc94394b327ceec71b3848faebd70311337f835ffbf3c986fe99387eb3e138 |
|
MD5 | 7409d691e13de3ed9e5fd0ee7a2346bf |
|
BLAKE2b-256 | 0b77b9d0e81f56724ebc2dd23330f502dc2e9bb92b8827b6fa7503cea22595e9 |
File details
Details for the file irspack-0.2.2-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 707.5 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9df460e6c6bcccf2e50087e2f49c37fc984cdcb85d0391b94b4a1bebfc0b1b87 |
|
MD5 | 3feee9c94017bd26db40295259901ecd |
|
BLAKE2b-256 | 37a4b70d8a7cb0e3726184a597c2a9107f84b7643124e027517c45ab57f54254 |
File details
Details for the file irspack-0.2.2-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: irspack-0.2.2-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 567.6 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9c4d1a2a37151b6defaa57b8f505cacf0b6ac3b42c724e0f3b0e79ca6fe789a |
|
MD5 | 2c5b8986dbe538e63c513cb91cb1e08a |
|
BLAKE2b-256 | ecbbc46220de4029f8a15ec6800f288401916d0552935d19aea956d60fd2a0cb |