Skip to content

Commit 09629c6

Browse files
committed
doc
1 parent 953b326 commit 09629c6

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

python/pyspark/mllib/recommendation.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ class MatrixFactorizationModel(JavaModelWrapper, JavaSaveable, JavaLoader):
6666
[(1, array('d', [...])), (2, array('d', [...]))]
6767
6868
>>> model.recommendUsers(1, 2)
69-
(Rating(user=2, product=1, rating=1.9...), Rating(user=1, product=1, rating=1.0...))
69+
[Rating(user=2, product=1, rating=1.9...), Rating(user=1, product=1, rating=1.0...)]
7070
>>> model.recommendProducts(1, 2)
71-
(Rating(user=1, product=2, rating=1.9...), Rating(user=1, product=1, rating=1.0...))
71+
[Rating(user=1, product=2, rating=1.9...), Rating(user=1, product=1, rating=1.0...)]
7272
>>> model.rank
7373
4
7474
@@ -113,13 +113,13 @@ class MatrixFactorizationModel(JavaModelWrapper, JavaSaveable, JavaLoader):
113113
"""
114114
def predict(self, user, product):
115115
"""
116-
Predicts rating for a given user and product.
116+
Predicts rating for the given user and product.
117117
"""
118118
return self._java_model.predict(int(user), int(product))
119119

120120
def predictAll(self, user_product):
121121
"""
122-
Returns a list of predicted Ratings for a user and many products.
122+
Returns a list of predicted ratings for input user and product pairs.
123123
"""
124124
assert isinstance(user_product, RDD), "user_product should be RDD of (user, product)"
125125
first = user_product.first()
@@ -129,33 +129,31 @@ def predictAll(self, user_product):
129129

130130
def userFeatures(self):
131131
"""
132-
Returns a coupled RDD, where the first element is the user and the
132+
Returns a paired RDD, where the first element is the user and the
133133
second is an array of features corresponding to that user.
134134
"""
135135
return self.call("getUserFeatures").mapValues(lambda v: array.array('d', v))
136136

137137
def productFeatures(self):
138138
"""
139-
Returns a coupled RDD, where the first element is the product and the
139+
Returns a paired RDD, where the first element is the product and the
140140
second is an array of features corresponding to that product.
141141
"""
142142
return self.call("getProductFeatures").mapValues(lambda v: array.array('d', v))
143143

144144
def recommendUsers(self, product, num):
145145
"""
146-
Recommends the top "num" number of products for a given user.
147-
This is done by returning a tuple of Rating objects, the second id (product)
148-
being constant and sorted according to the rating.
146+
Recommends the top "num" number of users for a given product and returns a list
147+
of Rating objects sorted by the predicted rating in descending order.
149148
"""
150-
return self.call("recommendUsers", product, num)
149+
return list(self.call("recommendUsers", product, num))
151150

152151
def recommendProducts(self, user, num):
153152
"""
154-
Recommends the top "num" number of products for a given user.
155-
This is done by returning a tuple of Rating objects, the first id (user)
156-
being constant and sorted according to the rating.
153+
Recommends the top "num" number of products for a given user and returns a list
154+
of Rating objects sorted by the predicted rating in descending order.
157155
"""
158-
return self.call("recommendProducts", user, num)
156+
return list(self.call("recommendProducts", user, num))
159157

160158
@property
161159
def rank(self):

0 commit comments

Comments
 (0)