Implicit is a Python library that provides fast Python implementations of popular collaborative filtering recommendation algorithms for implicit feedback datasets. It includes models like Alternating Least Squares (ALS), BPR (Bayesian Personalized Ranking), and various Nearest-Neighbours models. The library leverages Cython, NumPy, and SciPy for performance, with optional GPU acceleration using CUDA. The current version is 0.7.2, and new versions are released periodically, often every few months, with a focus on performance, new features, and bug fixes.
pip install implicitVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to train an AlternatingLeastSquares model on a sparse user-item interaction matrix and then generate recommendations for a user and find similar items. The input matrix must be a `scipy.sparse.csr_matrix`.
Specifically, `model.fit()` now expects a `user_items` matrix (users x items) instead of `item_users`. Additionally, recommendation methods (`model.recommend()`, `model.similar_items()`) now return NumPy arrays instead of lists of tuples. Consult the v0.5.0 release notes and current documentation.
Always convert your interaction data into a `scipy.sparse.csr_matrix` (Compressed Sparse Row) before passing it to `model.fit()`. For example, `user_items = csr_matrix(your_data)`.
Install with `pip install implicit[gpu]`. Ensure your NVIDIA drivers and CUDA Toolkit version are compatible with `CuPy`, the underlying library used for GPU computation. Refer to the CuPy documentation for system requirements.
Implicit uses `threadpoolctl` to help manage BLAS threading. However, if you encounter performance issues, explicitly control the number of threads for BLAS/OpenMP via environment variables (e.g., `OMP_NUM_THREADS`, `MKL_NUM_THREADS`) or by using `threadpoolctl` directly.
Install the library using pip: `pip install implicit` or, for GPU support or specific configurations, `conda install -c conda-forge implicit` (CPU only) or `conda install -c conda-forge implicit implicit-proc=*=gpu` (CPU+GPU).
Import `AlternatingLeastSquares` specifically from `implicit.als`: `from implicit.als import AlternatingLeastSquares`.
Ensure the NVIDIA CUDA Toolkit is installed (version 11 or later is required for implicit v0.7.2) and that `nvcc` is on your system's PATH. Reinstall `implicit` with GPU support, potentially setting the `CUDAHOME` environment variable if `nvcc` is not automatically found. For conda users, install with `conda install -c conda-forge implicit implicit-proc=*=gpu`.
Ensure that the `user_items` matrix passed to `model.recommend(userid, user_items)` is a slice of your full user-item matrix corresponding *only* to the `userid` being processed, or a matrix with the correct dimensions if recommending for multiple users. For a single user, `user_item_data[userid]` is typically used.
Ensure all dependencies are up-to-date and compatible with `implicit` 0.7.2. Try updating SciPy (`pip install --upgrade scipy`) and NumPy. Verify that the input matrices (e.g., `user_items` and `test_user_items`) are correctly formatted as sparse matrices (e.g., `csr_matrix` or `coo_matrix`) and contain appropriate data types before passing them to the evaluation functions.