Skip to main content

Neighbors

Build Status Coverage Status Python Versions Platforms

A Python package for collaborative filtering on social datasets

Installation

  1. Pip (official releases): pip install neighbors
  2. Github (bleeding edge): pip install git+https://github.com/cosanlab/neighbors.git

Getting started

The best way to learn how to use the package is by checking out the documentation site which contains usage tutorials as well as API documentation for all package functionality.

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
model.fit()

# If data are time-series optionally fit model using dilation
# to leverage auto-correlation and improve performance
model.fit(dilate_by_nsamples=60)

# Visualize results
model.plot_predictions()

# 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)

Algorithms

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

By default both NNMF models clip their predictions to the range of the observed ratings, since matrix factorization (and especially the unconstrained bias terms in NNMF_sgd) can otherwise produce predictions outside that range (e.g. negative values despite all-positive ratings). This is the same approach the Surprise package takes when making predictions, and can be disabled with .fit(clip_predictions=False). If the observed ratings don't span the full rating scale (e.g. no one used the top of a 1-5 scale), pass the scale explicitly with .fit(clip_range=(1, 5)).

Metadata

Release files for neighbors 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neighbors 0.2.1
File Size Uploaded
neighbors-0.2.1.tar.gz 1.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for neighbors 0.2.1
File Interpreter ABI Platform
neighbors-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 2.5 MB

Release files / neighbors-0.2.1.tar.gz

Download URL neighbors-0.2.1.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
273aa171bc867ba75672ce4284fea237b8ccebfb69325e3fe4197eeaba087314
BLAKE2b-256 checksum
How to use checksums
afb0652d7967cb85290ee5cd7ed6a273e9a2700f1d8c097d6b8205a75abb32ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / neighbors-0.2.1-py3-none-any.whl

Download URL neighbors-0.2.1-py3-none-any.whl
Size 898.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
061be09504ab3e841a116d218bbfca7c459fa5b740423fb0bfb86c45c81fd542
BLAKE2b-256 checksum
How to use checksums
abd11af5805d4c09244ad4fb52a3d7e590edd7dbb7341be9327153282445fc3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page