forked from chenshouyuan/crab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-svd.py
More file actions
31 lines (26 loc) · 1.5 KB
/
example-svd.py
File metadata and controls
31 lines (26 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from ..scikits.crab.models import MatrixPreferenceDataModel
from ..scikits.crab.metrics.pairwise import cosine_distances
from ..scikits.crab.similarities import ItemSimilarity
from ..scikits.crab.recommenders.svd.classes import MatrixFactorBasedRecommender
movies = {'Marcel Caraciolo': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.5,
'Just My Luck': 3.0, 'Superman Returns': 3.5, 'You, Me and Dupree': 2.5,
'The Night Listener': 3.0},
'Luciana Nunes': {'Lady in the Water': 3.0, 'Snakes on a Plane': 3.5,
'Just My Luck': 1.5, 'Superman Returns': 5.0, 'The Night Listener': 3.0,
'You, Me and Dupree': 3.5},
'Leopoldo Pires': {'Lady in the Water': 2.5, 'Snakes on a Plane': 3.0,
'Superman Returns': 3.5, 'The Night Listener': 4.0},
'Lorena Abreu': {'Snakes on a Plane': 3.5, 'Just My Luck': 3.0,
'The Night Listener': 4.5, 'Superman Returns': 4.0,
'You, Me and Dupree': 2.5},
'Steve Gates': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,
'Just My Luck': 2.0, 'Superman Returns': 3.0, 'The Night Listener': 3.0,
'You, Me and Dupree': 2.0},
'Sheldom': {'Lady in the Water': 3.0, 'Snakes on a Plane': 4.0,
'The Night Listener': 3.0, 'Superman Returns': 5.0, 'You, Me and Dupree': 3.5},
'Penny Frewman': {'Snakes on a Plane': 4.5, 'You, Me and Dupree': 1.0, 'Superman Returns': 4.0},
'Maria Gabriela': {}}
model = MatrixPreferenceDataModel(movies)
recommender = MatrixFactorBasedRecommender(model, n_features=10, learning_rate=0.01, regularization=0.02)
userid = 'Leopoldo Pires'
print recommender.recommend(userid)