Skip to main content

skrecsys

PyPI Python License: MIT

Recommender systems in the scikit-learn style, built on NumPy, SciPy and scikit-learn.

skrecsys is a prototype of the recommender estimator API proposed in docs/slep_recommender_systems.md: a RecommenderMixin with a common fit / predict / recommend contract, top-k ranking metrics, a warm-start cross-validation splitter and classical collaborative-filtering estimators.

Status: early alpha — the API is not stable yet.

Installation

pip install skrecsys

or with uv:

uv add skrecsys

Requires Python 3.11+, on Linux, macOS or Windows.

Usage

Training data is an array of shape (n_interactions, 2) of user and item identifiers, with an optional interaction value y.

import numpy as np
from sklearn.model_selection import GridSearchCV

from skrecsys.metrics import make_recommender_scorer, ndcg_at_k
from skrecsys.model_selection import WarmStartKFold
from skrecsys.recommendation import ItemKNNRecommender

X = np.array([["alice", "matrix"], ["alice", "alien"], ["bob", "matrix"], ...])

rec = ItemKNNRecommender(n_neighbors=50).fit(X)
items, scores = rec.recommend(["alice", "bob"], n_recommendations=5)

search = GridSearchCV(
    ItemKNNRecommender(),
    {"n_neighbors": [10, 50, 200], "shrink": [0.0, 10.0]},
    cv=WarmStartKFold(n_splits=5, shuffle=True, random_state=0),
    scoring=make_recommender_scorer(ndcg_at_k, k=10),
).fit(X)

Datasets

Loaders download public datasets once, cache them in ~/skrecsys_data (override with data_home= or SKRECSYS_DATA) and return them as (user_id, item_id) pairs plus ratings, like sklearn.datasets.

from sklearn.model_selection import cross_validate

from skrecsys.datasets import fetch_movielens_100k

X, y = fetch_movielens_100k(return_X_y=True)
cross_validate(
    ItemKNNRecommender(),
    X,
    y,
    cv=WarmStartKFold(n_splits=5, shuffle=True, random_state=0),
    scoring=make_recommender_scorer(ndcg_at_k, k=10),
)

# official u1-u5 / ua / ub splits, timestamps and user/movie metadata
ml = fetch_movielens_100k(subset="u1")
cross_validate(
    ItemKNNRecommender(),
    ml.data,
    ml.target,
    cv=[(ml.train_indices, ml.test_indices)],
    scoring=make_recommender_scorer(ndcg_at_k, k=10),
)

as_frame=True returns pandas objects and requires pip install skrecsys[pandas].

Leaderboard

MovieLens 100K, official ua split, k=10, default hyper-parameters. Regenerate with python benchmarks/leaderboard.py --write-readme.

Model NDCG@10 P@10 R@10 hit rate MAP MRR cat cov user cov mean pop novelty fit rec
EASE 0.2767 0.2382 0.2382 0.9035 0.1444 0.5888 0.3030 1.0000 228.8724 8.79 36 ms 27 ms
RP3Beta 0.2762 0.2407 0.2407 0.9215 0.1414 0.5911 0.2417 1.0000 235.4201 8.78 18 ms 16 ms
BM25 0.2661 0.2292 0.2292 0.8918 0.1370 0.5788 0.1024 1.0000 293.0034 8.36 12 ms 7 ms
ItemKNN 0.2550 0.2200 0.2200 0.9173 0.1268 0.5624 0.2887 1.0000 217.0530 8.86 155 ms 18 ms
MostPopular 0.1331 0.1215 0.1215 0.7306 0.0545 0.3218 0.0530 1.0000 371.7549 7.97 6 ms 1 ms
ALS 0.0422 0.0408 0.0408 0.3160 0.0144 0.1119 0.1464 1.0000 155.0729 10.09 348 ms 2 ms

Every model uses its default hyper-parameters, so this ranks the library's baselines, not the best each method can do. R@10 equals P@10 because the ua split holds out exactly 10 items per user, and user cov is 1 by construction: recommend raises rather than return a short list. The beyond-accuracy columns are the interesting ones — MostPopular has the highest mean pop and the lowest novelty, and BM25 buys its ranking score by covering a tenth of the catalog where EASE covers a third. fit and rec are median wall-clock times over --repeat runs; rec ranks the whole catalog for every held-out user in one batched call, which is not the same thing as the latency of a single user's request.

Scope

Module Contents Status
skrecsys RecommenderMixin, is_recommender implemented
skrecsys.metrics precision_at_k, recall_at_k, ndcg_at_k, average_precision_at_k, reciprocal_rank_at_k, hit_rate_at_k, make_recommender_scorer implemented
skrecsys.metrics catalog_coverage_at_k, user_coverage_at_k, mean_popularity_at_k, novelty_at_k, item_popularity implemented
skrecsys.datasets fetch_movielens_100k, get_data_home, clear_data_home implemented
skrecsys.model_selection WarmStartKFold implemented
skrecsys.utils.estimator_checks check_recommender, yield_recommender_checks implemented
skrecsys.recommendation MostPopularRecommender, ItemKNNRecommender, AlternatingLeastSquares, BM25Recommender, EASE, RP3Beta implemented
uv run python benchmarks/leaderboard.py                  # print the leaderboard
uv run python benchmarks/leaderboard.py --write-readme   # regenerate the table above

Development

Native kernels (for example the libFM-style ALS solver) are written in Rust under rust/ and built by maturin as skrecsys._core, so development needs a Rust toolchain (rustup or your package manager). uv sync rebuilds the extension when Rust sources change.

git clone https://github.com/mrk-andreev/skrecsys.git
cd skrecsys
uv sync
uv run pytest
uv run pytest -m benchmark  # quality benchmarks on real datasets (downloads data)
LIBFM_BIN=/path/to/libfm/bin/libFM uv run pytest -m benchmark -k libfm  # ALS vs libFM
uv run --group reference pytest -m benchmark -k implicit  # BM25 vs implicit
uv run pytest -m benchmark -k rectools  # EASE vs RecTools (needs network on first run)
uv run pytest -m benchmark -k dacrema  # RP3Beta vs its reference framework (needs network)
uv run ruff check
uv run ty check
cargo test
cargo clippy --all-targets -- -D warnings

Releasing

  1. Bump the version: uv version --bump patch (or minor / major).
  2. Commit, then tag and push: git tag v$(uv version --short) && git push --tags.
  3. The Release GitHub Actions workflow builds and publishes to PyPI via Trusted Publishing.

License

MIT

Release files for skrecsys 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for skrecsys 0.2.0
File Size Uploaded
skrecsys-0.2.0.tar.gz 158.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for skrecsys 0.2.0
File
skrecsys-0.2.0-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
skrecsys-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details
skrecsys-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
skrecsys-0.2.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details

Total release size:3.1 MB

Release files / skrecsys-0.2.0.tar.gz

Download URL skrecsys-0.2.0.tar.gz
Size 158.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8c5a25cb21868f805d5a219d023d82dcb5d76dab256e4cf68beec29a925cd9b2
BLAKE2b-256 checksum
How to use checksums
61d825922b21483d9a54e4380bb6434c479d1ea424d3a15d26cca098c17ae14a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.16 {"installer":{"name":"uv","version":"0.12.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / skrecsys-0.2.0-cp311-abi3-win_amd64.whl

Download URL skrecsys-0.2.0-cp311-abi3-win_amd64.whl
Size 759.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
65fc29d4dc7a2d2334f4ac2e8ac79162363d953a4c08602d9d793d1a6387427f
BLAKE2b-256 checksum
How to use checksums
b5a7323f6926c52ecaa398067c43d2387d3590fc2cb3af1c744b76cc1e818db6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.16 {"installer":{"name":"uv","version":"0.12.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / skrecsys-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL skrecsys-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 987.3 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
9db78203311e6bf55809a4d36dcf50d84a1b0c9c328135e94e2fcac3c66f93e4
BLAKE2b-256 checksum
How to use checksums
a2a885f4725f5a817cb9220913548880fa017623c1491030c37ff2045f7bbdbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.16 {"installer":{"name":"uv","version":"0.12.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / skrecsys-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL skrecsys-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 615.5 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2938921f1342ec5570bf91734dee34d07d19c754b4a75f5d7c92d9b0a594c61f
BLAKE2b-256 checksum
How to use checksums
a4f445be0fff78fa33632902edd38473a77cc02a2257329514a5d961b09c4ad8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.16 {"installer":{"name":"uv","version":"0.12.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / skrecsys-0.2.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL skrecsys-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Size 531.7 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8be075fa2d802c24b0d8ae366799d5be03ee12a5a0cdb24e2449be2c993eb202
BLAKE2b-256 checksum
How to use checksums
483a93a28cb1ec34f86ee55ecb993623e0bdcd01e1492fd486ab892c279b9173
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.16 {"installer":{"name":"uv","version":"0.12.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.3.0

5 release files

This release

0.2.0 This release

5 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page