{"id":6672,"library":"implicit","title":"Implicit Collaborative Filtering","description":"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.","status":"active","version":"0.7.2","language":"en","source_language":"en","source_url":"https://github.com/benfred/implicit/","tags":["recommendation-systems","collaborative-filtering","machine-learning","implicit-feedback","als","bpr","gpu-acceleration"],"install":[{"cmd":"pip install implicit","lang":"bash","label":"CPU-only installation"},{"cmd":"pip install implicit[gpu]","lang":"bash","label":"GPU-enabled installation (requires CUDA Toolkit)"}],"dependencies":[{"reason":"Core numerical operations and array handling.","package":"numpy","optional":false},{"reason":"Sparse matrix operations (e.g., csr_matrix) are fundamental inputs.","package":"scipy","optional":false},{"reason":"Used for detecting and controlling the number of threads used by BLAS/LAPACK libraries to prevent oversubscription.","package":"threadpoolctl","optional":false},{"reason":"Required for GPU acceleration with the 'gpu' extra. Requires a compatible CUDA Toolkit installation.","package":"cupy","optional":true}],"imports":[{"symbol":"AlternatingLeastSquares","correct":"from implicit.als import AlternatingLeastSquares"},{"symbol":"CosineRecommender","correct":"from implicit.nearest_neighbours import CosineRecommender"},{"symbol":"BM25Recommender","correct":"from implicit.nearest_neighbours import BM25Recommender"},{"note":"The FactorizationMachines model was moved to factorization_machines in older versions, but the primary module is now implicit.fm.  Ensure you use the correct module path for your installed version. As of 0.7.x, implicit.factorization_machines is correct.","wrong":"from implicit.fm import FactorizationMachines","symbol":"FactorizationMachines","correct":"from implicit.factorization_machines import FactorizationMachines"}],"quickstart":{"code":"import numpy as np\nfrom scipy.sparse import csr_matrix\nfrom implicit.als import AlternatingLeastSquares\n\n# Sample data: user-item interactions (user_id, item_id, strength)\ndata = np.array([1, 1, 1, 1, 1, 1])\nrows = np.array([0, 0, 1, 1, 2, 2]) # User IDs\ncols = np.array([0, 1, 1, 2, 0, 2]) # Item IDs\n\n# Create a sparse user-item matrix (users x items)\n# This is typically a CSR matrix for performance and compatibility.\nuser_items = csr_matrix((data, (rows, cols)), dtype=np.float32)\n\n# Initialize and train the AlternatingLeastSquares model\nmodel = AlternatingLeastSquares(factors=64, regularization=0.01, iterations=20, random_state=42)\nmodel.fit(user_items) # Model expects user_items (users x items) matrix\n\n# Recommend items for a specific user (e.g., user 0)\nuser_id = 0\n# The recommend method takes the user_id and the user_items matrix for that user.\nrecommended_items, scores = model.recommend(user_id, user_items[user_id])\n\nprint(f\"Recommended items for user {user_id}: {recommended_items}\")\nprint(f\"Scores: {scores}\")\n\n# Get similar items for a specific item (e.g., item 0)\nitem_id = 0\nsimilar_items, scores = model.similar_items(item_id)\nprint(f\"Items similar to item {item_id}: {similar_items}\")\nprint(f\"Scores: {scores}\")","lang":"python","description":"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`."},"warnings":[{"fix":"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.","message":"The API for `implicit` underwent substantial breaking changes in v0.5.0. Code written for versions prior to 0.5.0 will need to be rewritten.","severity":"breaking","affected_versions":"<0.5.0"},{"fix":"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)`.","message":"Model training methods (e.g., `model.fit()`) often require input matrices to be in `scipy.sparse.csr_matrix` format for optimal performance and correctness.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"Using GPU acceleration requires specific setup, including installing the `implicit[gpu]` extra and having a compatible CUDA Toolkit installed and configured on your system.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"When running on multi-core CPUs with BLAS/LAPACK libraries (like OpenBLAS, MKL), implicit threading can sometimes lead to oversubscription and performance degradation.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}