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.
Now algorithms objects are serialized. Trainsets are not dumped anymore as they are in the algorithm objects anyway. changed the load_algo function to simply 'load'. Added FAQ entry to serialize algorithms along with an example.
- Loading branch information
1 parent
d55ac43
commit 9e759a3
Showing
10 changed files
with
146 additions
and
76 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
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
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,33 @@ | ||
""" | ||
This module illustrates the use of the dump and load methods for serializing an | ||
algorithm. The SVD algorithm is trained on a dataset and then serialized. It is | ||
then reloaded and can be used again for making predictions. | ||
""" | ||
|
||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
import os | ||
|
||
from surprise import SVD | ||
from surprise import Dataset | ||
from surprise import dump | ||
|
||
|
||
data = Dataset.load_builtin('ml-100k') | ||
trainset = data.build_full_trainset() | ||
|
||
algo = SVD() | ||
algo.train(trainset) | ||
|
||
# Compute predictions of the 'original' algorithm. | ||
predictions = algo.test(trainset.build_testset()) | ||
|
||
# Dump algorithm and reload it. | ||
file_name = os.path.expanduser('~/dump_file') | ||
dump.dump(file_name, algo=algo) | ||
_, loaded_algo = dump.load(file_name) | ||
|
||
# We now ensure that the algo is still the same by checking the predictions. | ||
predictions_loaded_algo = loaded_algo.test(trainset.build_testset()) | ||
assert predictions == predictions_loaded_algo | ||
print('Predictions are the same') |
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