Skip to main content

Recommender systems for Python

Project description

https://api.travis-ci.org/ssaamm/PyRecs.svg?branch=master&service=github https://coveralls.io/repos/github/ssaamm/PyRecs/badge.svg?branch=master

A Python Recommender Systems library

Installation

I have only tested on Python 3.5.1

pip3 install pyrecs

Usage

Loading data from a Pandas DataFrame:

>>> import io
>>> import pandas as pd
>>> from pyrecs import collab
>>>
>>> df = pd.read_csv(io.StringIO("""
...        ,Torchy's,Tacodeli,In-N-Out,P. Terry's,Casa de Luz,Koriente
... Sam,           5,        ,       4,         4,          3,       1
... Matthew,        ,       2,       1,          ,          5,       5
... Sarah,         5,       4,       2,         2,          5,       5
... Hannah,         ,        ,       1,         1,          5,
... """.replace(' ', '')), index_col=0)
>>>
>>> cf = collab.CollaborativeFiltering()
>>> cf.fit(df)
>>> print(cf.predict([('Sam', 'Tacodeli'), ('Hannah', 'Koriente')]))
[ 3.41666667  5.76851363]

Predicting ratings based on training data:

>>> import numpy as np
>>> import pyrecs
>>> from sklearn.cross_validation import train_test_split
>>>
>>> data = [[10,     3.4, np.nan, None],
...         [10,     0,   10,     5],
...         [np.nan, 1.4, 10,     3],
...         [np.nan, 8,   2,      5]]
>>>
>>> X, y = pyrecs.collab.matrix_to_dataset(data)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y)
>>>
>>> cf = pyrecs.collab.CollaborativeFiltering()
>>> cf.fit(X_train, y_train)
>>>
>>> cf.predict(X_test)
array([ 0.25,  3.4 ,  9.75])
>>> y_test
[1.4, 10, 8]

Tests

py.test tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyRecs-0.0.2.tar.gz (3.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page