forked from NicolasHug/Surprise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added load_from_df() to load a dataset from a pandas dataframe
- Loading branch information
1 parent
bbc0dab
commit 757c9a1
Showing
11 changed files
with
192 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
Current | ||
======= | ||
|
||
* Added possibility to load a dataset from a pandas dataframe | ||
|
||
VERSION 1.0.3 | ||
============= | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ slope_one | |
accuracies | ||
NN | ||
deserialize | ||
dataframe | ||
dataframes | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
This module descibes how to load a dataset from a pandas dataframe. | ||
""" | ||
|
||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
import pandas as pd | ||
|
||
from surprise import NormalPredictor | ||
from surprise import Dataset | ||
from surprise import Reader | ||
|
||
|
||
# Dummy algo | ||
algo = NormalPredictor() | ||
|
||
# Creation of the dataframe. Column names are irrelevant. | ||
ratings_dict = {'itemID': [1, 1, 1, 2, 2], | ||
'userID': [9, 32, 2, 45, 'user_foo'], | ||
'rating': [3, 2, 4, 3, 1]} | ||
df = pd.DataFrame(ratings_dict) | ||
|
||
# A reader is still needed but only the rating_scale param is requiered. | ||
reader = Reader(rating_scale=(1, 5)) | ||
# The columns must correspond to user id, item id and ratings (in that order). | ||
data = Dataset.load_from_df(df[['userID', 'itemID', 'rating']], reader) | ||
data.split(2) # data can now be used normally | ||
|
||
for trainset, testset in data.folds(): | ||
algo.train(trainset) | ||
algo.test(testset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ sphinx_rtd_theme | |
sphinxcontrib-bibtex | ||
sphinxcontrib-spelling | ||
flake8>=3.2.1 | ||
pandas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters