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.
- Loading branch information
1 parent
c52385f
commit 8bc21cf
Showing
3 changed files
with
86 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
This module is used for generating the doc tables about the | ||
GridSearchCV.cv_results attribute. | ||
""" | ||
|
||
from __future__ import (absolute_import, division, print_function, | ||
unicode_literals) | ||
|
||
from tabulate import tabulate | ||
from six import iteritems | ||
|
||
from surprise import SVD | ||
from surprise import Dataset | ||
from surprise.model_selection import GridSearchCV | ||
|
||
# Use movielens-100K | ||
data = Dataset.load_builtin('ml-100k') | ||
|
||
param_grid = {'n_epochs': [5, 10], 'lr_all': [0.002, 0.005], | ||
'reg_all': [0.4, 0.6]} | ||
gs = GridSearchCV(SVD, param_grid, measures=['rmse', 'mae'], cv=3) | ||
|
||
gs.fit(data) | ||
|
||
table = [[] for _ in range(len(gs.cv_results['params']))] | ||
for i in range(len(gs.cv_results['params'])): | ||
for key in gs.cv_results.keys(): | ||
table[i].append(gs.cv_results[key][i]) | ||
|
||
header = gs.cv_results.keys() | ||
print(tabulate(table, header, tablefmt="rst")) | ||
|
||
print() | ||
|
||
for key, val in iteritems(gs.cv_results): | ||
print('{:<20}'.format("'" + key + "':"), end='') | ||
if isinstance(val[0], float): | ||
print([float('{:.2f}'.format(f)) for f in val]) | ||
else: | ||
print(val) |
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