Skip to content


Build Status Coverage Status Python Versions Platforms

A Python package for collaborative filtering on social and emotion datasets


  1. Pip (official releases): pip install neighbors
  2. Github (bleeding edge): pip install git+

Getting started

The best way to learn how to use the package is by checking out the 3 usage tutorials on working with dense, sparse, and time-series. For more detailed usage on specific function arguments and model parameters check out the API reference on the left.

Quick Demo Usage

from neighbors.models import NNMF_sgd
from neighbors.utils import create_user_item_matrix, estimate_performance

# Assuming data is 3 column pandas df with 'User', 'Item', 'Rating'
# convert it to a (possibly sparse) user x item matrix
mat = create_user_item_matrix(df)

# Initialize a model
model = NNMF_sgd(mat)

# Fit

# If data are time-series optionally fit model using dilation
# to leverage auto-correlation and improve performance

# Visualize results

# Estimate algorithm performance using
# Repeated refitting with random masking (dense data)
# Or cross-validation (sparse data)
group_results, user_results = estimate_performance(NNMF_sgd, mat)


Currently supported algorithms include:

  • Mean - a baseline model
  • KNN - k-nearest neighbors
  • NNMF_mult - non-negative matrix factorization trained via multiplicative updating
  • NNMF_sgd - non-negative matrix factorization trained via stochastic gradient descent