NeuralRecommender is a PyTorch implementation of a number of recommendation algorithms using neural networks.
As of now it implements:
Install from pip
:
pip install neuralrecommender
Fitting a model on the MovieLens 100k dataset:
import numpy as np
import ml_metrics
from neuralrecommender.glocalk import GlocalK
# Load the MovieLens 100k dataset.
def load_data_100k():
... # code in example notebook
return
n_m, n_u, train_r, train_m, test_r, test_m = load_data_100k()
# Instantiate and train the model
recommender = GlocalK()
metrics = recommender.fit(train_r)
# Recommend for all users
res = recommender.predict(np.arange(n_u))
# Evaluate the recommendations
k=50
ground_truth = np.argsort(-test_r, axis=0)[:k,:].T.tolist()
recommended = np.argsort(-res, axis=0)[:k,:].T.tolist()
random = np.random.randint(0,n_m,(n_u, k)).T.tolist()
ml_metrics.mapk(ground_truth, random, k=k)
ml_metrics.mapk(ground_truth, recommended, k=k)
- GLocal-K: Global and Local Kernels for Recommender Systems
- GLocal-K official implementation
- Harper, F. M., & Konstan, J. A. (2015). The movielens datasets: History and context. Acm transactions on interactive intelligent systems (tiis), 5(4), 1-19.