Registry / ai-ml / lightfm

lightfm

JSON →
library1.17pypypiunverified

LightFM is a Python implementation of the LightFM hybrid recommendation algorithm, combining collaborative and content-based filtering. Current version is 1.17. Release cadence is irregular.

pip install lightfm
INSTALL
IMPORT
SIG · LIGHTFM
L
lightfm
ai-mlpythonv1.17
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LightFM
from lightfm import LightFM
cross_validate
from lightfm.cross_validation import cross_validate
from lightfm.evaluation import cross_validate
cross_validate moved to cross_validation submodule in v1.16
precision_at_k
from lightfm.evaluation import precision_at_k
recall_at_k
from lightfm.evaluation import recall_at_k
auc_score
from lightfm.evaluation import auc_score

Basic usage: train a WARP-loss model on MovieLens data and evaluate precision@10.

import numpy as np from lightfm import LightFM from lightfm.datasets import fetch_movielens data = fetch_movielens(min_rating=4.0) model = LightFM(loss='warp') model.fit(data['train'], epochs=30, num_threads=2) from lightfm.evaluation import precision_at_k test_precision = precision_at_k(model, data['test'], k=10).mean() print(f'Test precision: {test_precision:.2f}')
Debug
Known issues
breakingIn v1.16, cross_validate was moved from lightfm.evaluation to lightfm.cross_validation. Old imports will break.
fix
Use 'from lightfm.cross_validation import cross_validate'.
affects: >=1.16
gotchaLightFM's fit method does not shuffle data internally. Always shuffle your training interactions (e.g., by using a random seed) to avoid order bias.
fix
Manually shuffle your item-user interaction matrix before passing to fit.
affects: all
gotchaThe predict method returns raw interaction scores (not probabilities). These can be negative and are not calibrated.
fix
Do not treat scores as probabilities; use ranking metrics for evaluation.
affects: all
deprecatedPython 3.6 and earlier are no longer supported. Ensure you use Python 3.7+.
fix
Upgrade to Python 3.7 or later.
affects: <=1.16
Upgrade
Version history
1.17latest on PyPI · released Mar 20, 2023
Audit
Dependencies
numpyrequiredrequired for array operations
scipyrequiredrequired for sparse matrix support
Agent activity
19 hits · last 30 days
node
16
Resources
lightfm — pip install lightfm · libregistry