Recommender systems for Python
Project description
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 details)
File details
Details for the file PyRecs-0.0.2.tar.gz
.
File metadata
- Download URL: PyRecs-0.0.2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cc59bfbe53a7de6f894bdf9a035dc9b29dbe2263d3d8b4ef904e2dc6d85e92f |
|
MD5 | 197b37da40d07aeba23b08199da7e0bc |
|
BLAKE2b-256 | bad5afd92ed03fc6782e785957a51b56f1dd623f6f2e694b9d094948bcb40f61 |