Skip to main content

Implicit feedback-based recommender system pack

Project description

irspack

Python pypi GitHub license Build Read the Docs codecov

Docs

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

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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

irspack-0.2.1.tar.gz (139.0 kB view details)

Uploaded Source

Built Distributions

irspack-0.2.1-cp310-cp310-win_amd64.whl (563.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

irspack-0.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.8 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

irspack-0.2.1-cp310-cp310-macosx_10_9_universal2.whl (1.3 MB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

irspack-0.2.1-cp39-cp39-win_amd64.whl (557.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

irspack-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

irspack-0.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.8 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

irspack-0.2.1-cp39-cp39-macosx_10_9_universal2.whl (1.3 MB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

irspack-0.2.1-cp38-cp38-win_amd64.whl (563.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

irspack-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.8 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

irspack-0.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.8 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

irspack-0.2.1-cp38-cp38-macosx_10_9_x86_64.whl (709.4 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

irspack-0.2.1-cp37-cp37m-win_amd64.whl (563.4 kB view details)

Uploaded CPython 3.7m Windows x86-64

irspack-0.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (11.0 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

irspack-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (10.7 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

irspack-0.2.1-cp37-cp37m-macosx_10_9_x86_64.whl (702.8 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

irspack-0.2.1-cp36-cp36m-win_amd64.whl (563.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

File details

Details for the file irspack-0.2.1.tar.gz.

File metadata

  • Download URL: irspack-0.2.1.tar.gz
  • Upload date:
  • Size: 139.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1.tar.gz
Algorithm Hash digest
SHA256 045695df75e1635cbed97fbfd41d8117b5c15f7d447fb39200f9374325cece8e
MD5 6b4c25175fe4be4080c68056c01c1f7e
BLAKE2b-256 b69c5777cc2f2e43f988a9617a18877806b869ffe34ebc36b7bf379be80d9bef

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: irspack-0.2.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 563.3 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ad0a82a17b83cd794c87bda7ea9b3ed8a0cab361a46f879a6aa2c1fd53b064f5
MD5 ba6c15fb67d6a08aaffdfe13f04a72d3
BLAKE2b-256 1ea7ae5424ac2b1d85e5a259cb55b68dcbf36ca5740dcbd94827b6aa7bd8a995

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for irspack-0.2.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0ee285a4377e0607f66715f5f198cc64d5f23c2fd6454249b20d93db973cb5b5
MD5 72029725ad6ac203ccf2bc252e84791d
BLAKE2b-256 6ec1beb46c26f7f09ef7c536e3f1929ab518c79b9141dfe41ef08aa0d60de003

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

  • Download URL: irspack-0.2.1-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.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 fffcdeb3bc28e143c9f05524baaad90ed37a476562d2b36142c4643442908d00
MD5 93f119dab43db6b927841e6ee7904a37
BLAKE2b-256 2656951335c23af198189f8f77ff0d4071ee5a787433f7f7c49bb99a489ff402

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: irspack-0.2.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 557.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1757c72f8aee1073443488e91c90a3cbb3449ae6939a010d3f84d1aeb1248b88
MD5 bb8178178031e2055b5a4174792f682e
BLAKE2b-256 4df67c7087ef3f1687aada86d06e6f831098591e8584b1fc4b456a82019ac553

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for irspack-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 200001878e5bb53eb35396b68c8226bab5ea16b6781dc9e2713ccef6c68b5a18
MD5 dc0b3bb2f86304bede9f9ef4a3f85d0e
BLAKE2b-256 0f4ad2a88e1676660d5464d39202c59c11ebedf4f33ebee90b1527cf8d7383ae

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for irspack-0.2.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8495a8e9b9545d1e8b95b7c23de7cb9f00e871eafa85f780f7911fd2c50ccaec
MD5 4ad20f6a234bc658aac9e77bef9915ed
BLAKE2b-256 68b19ce38c89ddf8a6069b686b13280b9d71d6d07bad518e179a570c84c38460

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

  • Download URL: irspack-0.2.1-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.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f190c97ae167ae57b9fb9304ad2a757ae6ab3bb109d96a6a86cfd85e2e5c0323
MD5 e22674a21b7bf7c334d2e18a9003d440
BLAKE2b-256 9e5505a48402318e3844d5cdb24134195d01df6064c24b7b6d1111a3d181a583

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: irspack-0.2.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 563.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f709333fea32d99ad55bc5243e45078f4faec1c80e8a8a56ca2c8315222b5c18
MD5 ae2b2bcc0f086e5080861cf8ed53a1d0
BLAKE2b-256 754d3000406027dc6dbedb448645a9f2fb5a1ead8827f79d3e6a1e04aa0f0513

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for irspack-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f26b001d4cb31918c0e015223f87909f5d9df966c65a44a3cdf98699fa16ff73
MD5 c605dcb102b776b50a5cc2d7b16b7b43
BLAKE2b-256 b6931d515b67c9e6dd24754eb6cedfff2131b68d5c8b0b01629de6bff36b9259

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for irspack-0.2.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7ea81893a7a4f9dbd7510c5c42ab101c97c5947f76617c04f4f0ff3e7f34dd5d
MD5 e1f0f52c5039b3b5dfd2f9ddecdd9e3b
BLAKE2b-256 6b06aadf24c3e677d5591e6e490f47667a1b5c3653508391e158479b1e75132f

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: irspack-0.2.1-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 709.4 kB
  • Tags: CPython 3.8, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c86de5b86ad42cb692ba41c00fbd18ec0fc746438fd0cf31357b15597658fe8d
MD5 25f70687beed99c68f37314a9dae0b4b
BLAKE2b-256 f5def2f4491932ee8a8b4cd277d8ad97f6e6c7e2cdf1504790122abbf1b47db3

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: irspack-0.2.1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 563.4 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 e312e6c405cc92c6a564cdaa6105f0ca8d475d2644c433c0e1b941f930a8b261
MD5 58c7ee89da26cb02b3e382c3d0829baf
BLAKE2b-256 d6467501f782fe54db917cb0f5b8fe3ab9dd46bbb8fc1eed9e34f82415ce15eb

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for irspack-0.2.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b2e781ce5705151c73461e17f4931c43ee024704cc748b70fa6d1299d73943c6
MD5 a6181394af12925a7834c5a4cd996537
BLAKE2b-256 057b9b2034afe80816794e0951729bba35169048c3f1291c599d61d1a61a92ae

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for irspack-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 72bd9b157d77624bae5500b8153b83ce41a19a4fd8969ee26330ae3ca24304cd
MD5 d787a81b574094001658513a3f5db805
BLAKE2b-256 044e1b5bca4eed37029d4bc5af81fc589ced480cd3dc588bb5331f1d54714ada

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: irspack-0.2.1-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 702.8 kB
  • Tags: CPython 3.7m, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d3d650f4fc9ce6d2294d5bdd75f8d04e83cea1f37d40220a6f2660763f3f295e
MD5 c2b7f2bee20c4674377d0665697f099d
BLAKE2b-256 11735aaf93b3ef9f2625963513e872ec0a6bf64dedeb8afc2827431592c176ca

See more details on using hashes here.

File details

Details for the file irspack-0.2.1-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: irspack-0.2.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 563.3 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for irspack-0.2.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 3ffb0d8495c2418ad79919d62a394ca60fd4cf5c49f9e4a47628faab581bc018
MD5 9ec125f3398907ef19b031c309cca3e0
BLAKE2b-256 464c3451c31a8ac15fb6b51975ee266125486c269f354520227b28c00c9d3c1a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page