aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorXiangrui Meng <meng@databricks.com>2015-02-02 23:49:09 -0800
committerXiangrui Meng <meng@databricks.com>2015-02-02 23:49:09 -0800
commit0cc7b88c99405db99bc4c3d66f5409e5da0e3c6e (patch)
tree954be2e5603e919a268ea9d68262586b2eb77ed4 /python
parentb8ebebeaaa259be4fcddf65b3280d23165b011a1 (diff)
downloadspark-0cc7b88c99405db99bc4c3d66f5409e5da0e3c6e.tar.gz
spark-0cc7b88c99405db99bc4c3d66f5409e5da0e3c6e.tar.bz2
spark-0cc7b88c99405db99bc4c3d66f5409e5da0e3c6e.zip
[SPARK-5536] replace old ALS implementation by the new one
The only issue is that `analyzeBlock` is removed, which was marked as a developer API. I didn't change other tests in the ALSSuite under `spark.mllib` to ensure that the implementation is correct. CC: srowen coderxiang Author: Xiangrui Meng <meng@databricks.com> Closes #4321 from mengxr/SPARK-5536 and squashes the following commits: 5a3cee8 [Xiangrui Meng] update python tests that are too strict e840acf [Xiangrui Meng] ignore scala style check for ALS.train e9a721c [Xiangrui Meng] update mima excludes 9ee6a36 [Xiangrui Meng] merge master 9a8aeac [Xiangrui Meng] update tests d8c3271 [Xiangrui Meng] remove analyzeBlocks d68eee7 [Xiangrui Meng] add checkpoint to new ALS 22a56f8 [Xiangrui Meng] wrap old ALS c387dff [Xiangrui Meng] support random seed 3bdf24b [Xiangrui Meng] make storage level configurable in the new ALS
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/mllib/recommendation.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/python/pyspark/mllib/recommendation.py b/python/pyspark/mllib/recommendation.py
index 97ec74eda0..0d99e6dedf 100644
--- a/python/pyspark/mllib/recommendation.py
+++ b/python/pyspark/mllib/recommendation.py
@@ -49,17 +49,17 @@ class MatrixFactorizationModel(JavaModelWrapper):
>>> r3 = (2, 1, 2.0)
>>> ratings = sc.parallelize([r1, r2, r3])
>>> model = ALS.trainImplicit(ratings, 1, seed=10)
- >>> model.predict(2,2)
- 0.4473...
+ >>> model.predict(2, 2)
+ 0.43...
>>> testset = sc.parallelize([(1, 2), (1, 1)])
- >>> model = ALS.train(ratings, 1, seed=10)
+ >>> model = ALS.train(ratings, 2, seed=0)
>>> model.predictAll(testset).collect()
- [Rating(user=1, product=1, rating=1.0471...), Rating(user=1, product=2, rating=1.9679...)]
+ [Rating(user=1, product=1, rating=1.0...), Rating(user=1, product=2, rating=1.9...)]
>>> model = ALS.train(ratings, 4, seed=10)
>>> model.userFeatures().collect()
- [(2, array('d', [...])), (1, array('d', [...]))]
+ [(1, array('d', [...])), (2, array('d', [...]))]
>>> first_user = model.userFeatures().take(1)[0]
>>> latents = first_user[1]
@@ -67,7 +67,7 @@ class MatrixFactorizationModel(JavaModelWrapper):
True
>>> model.productFeatures().collect()
- [(2, array('d', [...])), (1, array('d', [...]))]
+ [(1, array('d', [...])), (2, array('d', [...]))]
>>> first_product = model.productFeatures().take(1)[0]
>>> latents = first_product[1]
@@ -76,11 +76,11 @@ class MatrixFactorizationModel(JavaModelWrapper):
>>> model = ALS.train(ratings, 1, nonnegative=True, seed=10)
>>> model.predict(2,2)
- 3.735...
+ 3.8...
>>> model = ALS.trainImplicit(ratings, 1, nonnegative=True, seed=10)
>>> model.predict(2,2)
- 0.4473...
+ 0.43...
"""
def predict(self, user, product):
return self._java_model.predict(int(user), int(product))