Skip to main content

A realtime recommendation system supporting online updates

Project description

rtrec: Realtime Recommendation Library in Python

PyPI version Supported Python versions CI status Licence Open In Colab

A realtime recommendation system supporting online updates.

Highlights

Supported Recommendation Algorithims

  • Sparse SLIM with time-weighted interactions.
  • Factorization Machines using LightFM
  • Hybrid model of SLIM (CF) and Factorization Machines (CB). Based on the number of user-item interactions, balances prediction weights between CF and CB.

Installation

# using pip
pip install rtrec
pip install rtrec[serving]

# using uv
uv add rtrec
uv sync --no-extra serving

uv add rtrec[serving]
uv sync --extra serving

Usage

Find usages in notebooks/examples.

Examples using Raw-level APIs

# Dataset consists of user, item, tstamp, rating
import time
current_unixtime = time.time()
interactions = [('user_1', 'item_1', current_unixtime, 5.0),
                ('user_2', 'item_2', current_unixtime, -2.0),
                ('user_2', 'item_1', current_unixtime, 3.0),
                ('user_2', 'item_4', current_unixtime, 3.0),
                ('user_1', 'item_3', current_unixtime, 4.0)]

# Fit SLIM model
from rtrec.models import SLIM
model = SLIM()
model.fit(interactions)

# can fit from streams using yield as follows:
def yield_interactions():
    for interaction in interactions:
        yield interaction
model.fit(yield_interactions())

# Recommend top-5 items for a user
recommendations = model.recommend('user_1', top_k=5)
assert recommendations == ["item_4", "item_2"]

Examples using high level DataFrame APIs

# load dataset
from rtrec.experiments.datasets import load_dataset
df = load_dataset(name='movielens_1m')

# Split data set by temporal user split
from rtrec.experiments.split import temporal_user_split
train_df, test_df = temporal_user_split(df)

# Initialize SLIM model with custom options
from rtrec.recommender import Recommender
from rtrec.models import SLIM
model = SLIM(min_value=0, max_value=15, decay_in_days=180, nn_feature_selection=50)
recommender = Recommender(model)

# Bulk fit
recommender.bulk_fit(train_df)

# Partial fit
from rtrec.experiments.split import temporal_split
test_df1, test_df2 = temporal_split(test_df, test_frac=0.5)

recommender.fit(test_df1, update_interaction=True, parallel=True)

# Evaluation
metrics = recommender.evaluate(test_df2, recommend_size=10, filter_interacted=True)
print(metrics)

# User to Item Recommendation
recommended = recommender.recommend(user=10, top_k=10, filter_interacted=True)
assert len(recommended) == 10

# Item to Item recommendation
similar_items = recommender.similar_items(query_items=[3,10], top_k=5)
assert len(similar_items) == 2

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

rtrec-0.2.1.tar.gz (72.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rtrec-0.2.1-py3-none-any.whl (59.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rtrec-0.2.1.tar.gz
  • Upload date:
  • Size: 72.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for rtrec-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a9ed38bc79b80fc4545096d2dd3bc0de704c55f1e29206f8ee14f0b09bd9e270
MD5 721f15d21c610fdb0bdbcfef6ccf0fa7
BLAKE2b-256 b8deb7b171f48e07cf1c0d4a918bc4bf1cb6e8faf563d3e1f10c28eeb8f4c1ee

See more details on using hashes here.

File details

Details for the file rtrec-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: rtrec-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 59.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for rtrec-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92ab6363e17ba89d267912bbe85de755afb6f9629e8df0f4f9e3e188c04e2286
MD5 1344e20c5d68c6d5558e08557583a532
BLAKE2b-256 706c45e1748d4a5d4bc74cd0b49f085f73a6267b2efdd66274d0db7354370863

See more details on using hashes here.

Supported by

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