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.3.tar.gz
(3.4 kB
view details)
File details
Details for the file PyRecs-0.0.3.tar.gz
.
File metadata
- Download URL: PyRecs-0.0.3.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c9e3d049856e17e6fd19109b69640dfdb4800bf0273074b526747aad8a40e2e |
|
MD5 | d1c779163d049a94c6b4cc3b5050d9ae |
|
BLAKE2b-256 | 7b159884994809d01b5a47546d25cb60cff981c3edb572b613877a10cbf82294 |