Skip to content

Commit 6029d5c

Browse files
author
Kenneth Chan
committed
Merge branch 'develop'
2 parents bc4a6f9 + 35ecdf6 commit 6029d5c

File tree

13 files changed

+1737
-1594
lines changed

13 files changed

+1737
-1594
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.project
33
.pydevproject
44
.settings
5+
*.swp
56
build/
67
dist/
78
MANIFEST

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
# built documents.
5050
#
5151
# The short X.Y version.
52-
version = '0.6'
52+
version = '0.7'
5353
# The full version, including alpha/beta/rc tags.
54-
release = '0.6.3'
54+
release = '0.7.0'
5555

5656
# The language for content autogenerated by Sphinx. Refer to documentation
5757
# for a list of supported languages.

docs/source/predictionio.rst

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ Afterwards, you can import data or retrieve recommendations for your App by call
7979

8080
>>> result = client.get_itemsim_topn("engine-2", "i200", 5)
8181

82+
To get top 5 similar items given a list of items i200,i300,i400 from the item similarity engine "engine-2"
83+
84+
>>> result = client.get_itemsim_topn("engine-2", "i200,i300,i400", 5)
85+
86+
**Item Rank Engine**
87+
88+
To rank a list of items i100, i101, i102, i103 for user "u100" from the item rank engine "engine-3"
89+
90+
>>> client.identify("u100")
91+
>>> result = client.get_itemrank_ranked("engine-3", ["i100","i101","i102", "i103"])
92+
93+
8294
Please refer to the documentation of the :class:`predictionio.Client` class for more details of all available methods.
8395

8496

@@ -193,7 +205,7 @@ predictionio.Client Class
193205
.. automethod:: pending_requests
194206

195207
.. versionadded:: 0.6.1
196-
208+
197209
|
198210
199211
.. _sync-methods-label:
@@ -224,13 +236,17 @@ predictionio.Client Class
224236

225237
.. versionadded:: 0.6.0
226238

239+
.. automethod:: get_itemrank_ranked
240+
241+
.. versionadded:: 0.7.0
242+
227243
.. automethod:: get_itemrec
228-
244+
229245
.. deprecated:: 0.5.0
230246
Use :func:`get_itemrec_topn` instead.
231247

232248
.. automethod:: user_conversion_item
233-
249+
234250
.. deprecated:: 0.5.0
235251
Use :func:`record_action_on_item` instead.
236252

@@ -283,6 +299,10 @@ predictionio.Client Class
283299

284300
.. versionadded:: 0.6.0
285301

302+
.. automethod:: aget_itemrank_ranked
303+
304+
.. versionadded:: 0.7.0
305+
286306
.. automethod:: aget_itemrec
287307

288308
.. deprecated:: 0.5.0
@@ -314,5 +334,3 @@ predictionio.Client Class
314334
Use :func:`arecord_action_on_item` instead.
315335

316336
.. automethod:: aresp
317-
318-

examples/__init__.py

Whitespace-only changes.

examples/itemrec/__init__.py

Whitespace-only changes.

examples/itemrec/movies/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
PredictionIO Python SDK Example
2+
===============================
3+
4+
Please execute all commands from repository root.
5+
6+
Step 1. Get sample data and unzip it.
7+
8+
> wget http://www.grouplens.org/system/files/ml-100k.zip
9+
> unzip ml-100k.zip
10+
11+
Step 2. Configurate examples/itemrec/movies/appdata.py
12+
13+
Step 3. Run this app:
14+
15+
> python -m examples.itemrec.movies.movie_rec_app

examples/itemrec/movies/__init__.py

Whitespace-only changes.

examples/itemrec/movies/app_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
2-
APP_KEY = 'wWKeyokhpwEgis9BHCHkwqB7Hcop0OEF6KzkZWXfz2uMJYjl2QDwNlFVGl5hhHfy'
1+
APP_KEY = 'uJKTKyUAFNZYQQO5yxkdrSo3XIlaf9LXejI63CWE0mtZVEYF89hyVtOwpMKfXXXX'
32
API_URL = 'http://localhost:8000'
4-

examples/itemrec/movies/appdata.py

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -15,134 +15,134 @@
1515

1616

1717
class User:
18-
def __init__(self, uid):
19-
self.uid = uid
20-
self.rec = [] # recommendations, list of iid
18+
def __init__(self, uid):
19+
self.uid = uid
20+
self.rec = [] # recommendations, list of iid
2121

22-
def __str__(self):
23-
return "User[uid=%s,rec=%s]" % (self.uid, self.rec)
22+
def __str__(self):
23+
return "User[uid=%s,rec=%s]" % (self.uid, self.rec)
2424

2525
class Item:
26-
def __init__(self, iid, name):
27-
self.iid = iid
28-
self.name = name
26+
def __init__(self, iid, name):
27+
self.iid = iid
28+
self.name = name
2929

30-
def __str__(self):
31-
return "Item[iid=%s,name=%s]" % (self.iid, self.name)
30+
def __str__(self):
31+
return "Item[iid=%s,name=%s]" % (self.iid, self.name)
3232

3333
class RateAction:
34-
def __init__(self, uid, iid, rating, t):
35-
self.uid = uid
36-
self.iid = iid
37-
self.rating = rating
38-
self.t = t
34+
def __init__(self, uid, iid, rating, t):
35+
self.uid = uid
36+
self.iid = iid
37+
self.rating = rating
38+
self.t = t
3939

40-
def __str__(self):
41-
return "RateAction[uid=%s,iid=%s,rating=%s,t=%s]" % (self.uid, self.iid, self.rating, self.t)
40+
def __str__(self):
41+
return "RateAction[uid=%s,iid=%s,rating=%s,t=%s]" % (self.uid, self.iid, self.rating, self.t)
4242

4343

4444
class AppData:
4545

46-
def __init__(self):
47-
self._users = {} # dict of User obj
48-
self._items = {} # dict of Item obj
49-
self._rate_actions = [] # list of RateAction obj
50-
51-
self._users_file = "%s/%s" % (APPDATA_DIRNAME, USERS_FILENAME)
52-
self._items_file = "%s/%s" % (APPDATA_DIRNAME, ITEMS_FILENAME)
53-
self._rate_actions_file = "%s/%s" % (APPDATA_DIRNAME, RATE_ACTIONS_FILENAME)
54-
self.__init_users()
55-
self.__init_items()
56-
self.__init_rate_actions()
57-
58-
def __init_users(self):
59-
"""
60-
uid|
61-
"""
62-
print "[Info] Initializing users..."
63-
f = open(self._users_file, 'r')
64-
for line in f:
65-
data = line.rstrip('\r\n').split(USERS_FILE_DELIMITER)
66-
self.add_user(User(data[0]))
67-
f.close()
68-
print "[Info] %s users were initialized." % len(self._users)
69-
70-
def __init_items(self):
71-
"""
72-
iid|name
73-
"""
74-
print "[Info] Initializing items..."
75-
f = open(self._items_file, 'r')
76-
for line in f:
77-
data = line.rstrip('\r\n').split(ITEMS_FILE_DELIMITER)
78-
self.add_item(Item(data[0], data[1]))
79-
f.close()
80-
print "[Info] %s items were initialized." % len(self._items)
81-
82-
def __init_rate_actions(self):
83-
"""
84-
uid|iid|rating|timestamp
85-
"""
86-
print "[Info] Initializing rate actions..."
87-
f = open(self._rate_actions_file, 'r')
88-
for line in f:
89-
data = line.rstrip('\r\n').split(RATE_ACTIONS_DELIMITER)
90-
t = datetime.datetime.utcfromtimestamp(int(data[3])).isoformat()
91-
self.add_rate_action(RateAction(data[0], data[1], data[2], t))
92-
f.close()
93-
print "[Info] %s rate actions were initialized." % len(self._rate_actions)
94-
95-
def add_user(self, user):
96-
self._users[user.uid] = user
97-
98-
def add_item(self, item):
99-
self._items[item.iid] = item
100-
101-
def add_rate_action(self, action):
102-
self._rate_actions.append(action)
103-
104-
def get_users(self):
105-
return self._users
106-
107-
def get_items(self):
108-
return self._items
109-
110-
def get_rate_actions(self):
111-
return self._rate_actions
112-
113-
def get_user(self, uid):
114-
"""return single user
115-
"""
116-
if uid in self._users:
117-
return self._users[uid]
118-
else:
119-
return None
120-
121-
def get_item(self, iid):
122-
"""return single item
123-
"""
124-
if iid in self._items:
125-
return self._items[iid]
126-
else:
127-
return None
128-
129-
def get_top_rated_items(self, uid, n):
130-
"""get top n rated iids by this uid
131-
"""
132-
if uid in self._users:
133-
actions = filter(lambda u: u.uid==uid, self._rate_actions)
134-
top = sorted(actions, key=attrgetter('rating'), reverse=True)
135-
topn_iids = map(lambda a: a.iid, top[:n])
136-
return topn_iids
137-
else:
138-
return None
139-
140-
def get_top_rate_actions(self, uid, n):
141-
"""get top n rated actions by this uid
142-
"""
143-
if uid in self._users:
144-
actions = filter(lambda u: u.uid==uid, self._rate_actions)
145-
top = sorted(actions, key=attrgetter('rating'), reverse=True)
146-
return top[:n]
147-
else:
148-
return None
46+
def __init__(self):
47+
self._users = {} # dict of User obj
48+
self._items = {} # dict of Item obj
49+
self._rate_actions = [] # list of RateAction obj
50+
51+
self._users_file = "%s/%s" % (APPDATA_DIRNAME, USERS_FILENAME)
52+
self._items_file = "%s/%s" % (APPDATA_DIRNAME, ITEMS_FILENAME)
53+
self._rate_actions_file = "%s/%s" % (APPDATA_DIRNAME, RATE_ACTIONS_FILENAME)
54+
self.__init_users()
55+
self.__init_items()
56+
self.__init_rate_actions()
57+
58+
def __init_users(self):
59+
"""
60+
uid|
61+
"""
62+
print "[Info] Initializing users..."
63+
f = open(self._users_file, 'r')
64+
for line in f:
65+
data = line.rstrip('\r\n').split(USERS_FILE_DELIMITER)
66+
self.add_user(User(data[0]))
67+
f.close()
68+
print "[Info] %s users were initialized." % len(self._users)
69+
70+
def __init_items(self):
71+
"""
72+
iid|name
73+
"""
74+
print "[Info] Initializing items..."
75+
f = open(self._items_file, 'r')
76+
for line in f:
77+
data = line.rstrip('\r\n').split(ITEMS_FILE_DELIMITER)
78+
self.add_item(Item(data[0], data[1]))
79+
f.close()
80+
print "[Info] %s items were initialized." % len(self._items)
81+
82+
def __init_rate_actions(self):
83+
"""
84+
uid|iid|rating|timestamp
85+
"""
86+
print "[Info] Initializing rate actions..."
87+
f = open(self._rate_actions_file, 'r')
88+
for line in f:
89+
data = line.rstrip('\r\n').split(RATE_ACTIONS_DELIMITER)
90+
t = datetime.datetime.utcfromtimestamp(int(data[3])).isoformat()
91+
self.add_rate_action(RateAction(data[0], data[1], data[2], t))
92+
f.close()
93+
print "[Info] %s rate actions were initialized." % len(self._rate_actions)
94+
95+
def add_user(self, user):
96+
self._users[user.uid] = user
97+
98+
def add_item(self, item):
99+
self._items[item.iid] = item
100+
101+
def add_rate_action(self, action):
102+
self._rate_actions.append(action)
103+
104+
def get_users(self):
105+
return self._users
106+
107+
def get_items(self):
108+
return self._items
109+
110+
def get_rate_actions(self):
111+
return self._rate_actions
112+
113+
def get_user(self, uid):
114+
"""return single user
115+
"""
116+
if uid in self._users:
117+
return self._users[uid]
118+
else:
119+
return None
120+
121+
def get_item(self, iid):
122+
"""return single item
123+
"""
124+
if iid in self._items:
125+
return self._items[iid]
126+
else:
127+
return None
128+
129+
def get_top_rated_items(self, uid, n):
130+
"""get top n rated iids by this uid
131+
"""
132+
if uid in self._users:
133+
actions = filter(lambda u: u.uid==uid, self._rate_actions)
134+
top = sorted(actions, key=attrgetter('rating'), reverse=True)
135+
topn_iids = map(lambda a: a.iid, top[:n])
136+
return topn_iids
137+
else:
138+
return None
139+
140+
def get_top_rate_actions(self, uid, n):
141+
"""get top n rated actions by this uid
142+
"""
143+
if uid in self._users:
144+
actions = filter(lambda u: u.uid==uid, self._rate_actions)
145+
top = sorted(actions, key=attrgetter('rating'), reverse=True)
146+
return top[:n]
147+
else:
148+
return None

0 commit comments

Comments
 (0)