Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/3095#discussion_r19846425
--- Diff: python/pyspark/mllib/recommendation.py ---
@@ -69,6 +69,14 @@ class MatrixFactorizationModel(JavaModelWrapper):
>>> latents = first_product[1]
>>> len(latents) == 4
True
+
+ >>> model = ALS.train(ratings, 1, nonnegative=True)
+ >>> model.predict(2,2) is not None
+ True
--- End diff --
The non-deterministic could be removed by have a fixed `seed`, but right
now we can not set seed in Python (it will be great if you could also fix it).
How about these:
```
>>> r1 = (1, 1, 1.0)
>>> r2 = (1, 2, 2.0)
>>> r3 = (2, 1, 2.0)
>>> ratings = sc.parallelize([r1, r2, r3])
>>> model = ALS.trainImplicit(ratings, 1)
>>> model.predict(2,2)
0.4473...
>>> testset = sc.parallelize([(1, 2), (1, 1)])
>>> model = ALS.train(ratings, 1)
>>> model.predictAll(testset).collect()
[Rating(1, 1, 1), Rating(1, 2, 1)]
>>> model = ALS.train(ratings, 4)
>>> model.userFeatures().collect()
[(2, array('d', [...])), (1, array('d', [...]))]
>>> model.productFeatures().collect()
[(2, array('d', [...])), (1, array('d', [...]))]
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]