KNN Similarity Algorithms for Collaborative Filtering Models
Fast Python KNN-Similarity algorithms for Collaborative Filtering models in Recommender System and others.
This project provides fast Python implementations of several different popular KNN (K-Nearest Neighbors) similarity algorithms for Recommender System models.
Base similarity models:
- Dot Product
- Asymmetric Cosine
Graph-based similarity models:
Advanced similarity model:
[ Complete documentation coming soon... ] [ TODO ]
All models have multi-threaded routines, using Cython and OpenMP to fit the models in parallel among all available CPU cores.
pip install similaripy
import similaripy as sim import scipy.sparse as sps # create a random user-rating matrix (URM) urm = sps.random(1000, 2000, density=0.025) # train the model with 50 knn per item model = sim.cosine(urm.T, k=50) # recommend 100 items to users 1, 14 and 8 user_recommendations = sim.dot_product(urm, model, target_rows=[1,14,8], k=100)
For more information see the documentation. [ TODO ]
NOTE: In order to compile the Cython code it is required a GCC compiler with OpenMP
(on OSX it can be installed with homebrew:
brew install gcc).
This library has been tested with Python 3.6 on Ubuntu, OSX and Windows.
(Note: on Windows there are problem with flag format_output='csr', just let it equals to the default value 'coo')
I recommend configuring SciPy/Numpy to use Intel's MKL matrix libraries. The easiest way of doing this is by installing the Anaconda Python distribution.
I plan to release in the next future some utilities:
- Utilities for sparse matrices
- Pre-processing / post-processing functions (TF-IDF, BM25 and more)
- New similarity functions ( good ideas are welcome :) )
The idea of build this library comes from the RecSys Challenge 2018 organized by Spotify.
My team, the Creamy Fireflies, had problem in compute very huge similarity models in a reasonable time (66 million of interactions in the user-rating matrix) and using python and numpy were not suitable since a full day was required to compute one single model.
As a member of the the team I spent a lot of hours to develop these high-performance similarities in Cython to overcome the problem. At the end of the competition, pushed by my team friends, I decide to release my work to help people that one day will encounter our same problem.
Thanks to my Creamy Fireflies friends for support me.
Released under the MIT License
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size similaripy-0.0.9-cp36-cp36m-macosx_10_7_x86_64.whl (262.2 kB)||File type Wheel||Python version cp36||Upload date||Hashes View|
|Filename, size similaripy-0.0.9.tar.gz (132.0 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for similaripy-0.0.9-cp36-cp36m-macosx_10_7_x86_64.whl