MLlib MatrixFactorizationModel RecommendationProducts(user,num)在某些用户上失败 [英] MLlib MatrixFactorizationModel recommendProducts(user, num) failing on some users
问题描述
我训练了MatrixFactorizationModel
模型(org.apache.spark.rdd.RDD,%20int,%20int)"rel =" nofollow> ALS.train()
,现在使用
I trained a MatrixFactorizationModel
model using ALS.train()
and now using model.recommendProducts(user, num)
to get the top recommended products, but the code fails on some users with the following error:
user_products = model.call("recommendProducts", user, prodNum)
File "/usr/lib/spark/python/pyspark/mllib/common.py", line 136, in call
return callJavaFunc(self._sc, getattr(self._java_model, name), *a)
File "/usr/lib/spark/python/pyspark/mllib/common.py", line 113, in callJavaFunc
return _java2py(sc, func(*args))
File "/usr/lib/spark/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py", line 538, in __call__
File "/usr/lib/spark/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py", line 300, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o68.recommendProducts.
: java.util.NoSuchElementException: next on empty iterator
at scala.collection.Iterator$$anon$2.next(Iterator.scala:39)
at scala.collection.Iterator$$anon$2.next(Iterator.scala:37)
at scala.collection.IndexedSeqLike$Elements.next(IndexedSeqLike.scala:64)
at scala.collection.IterableLike$class.head(IterableLike.scala:91)
at scala.collection.mutable.WrappedArray.scala$collection$IndexedSeqOptimized$$super$head(WrappedArray.scala:34)
at scala.collection.IndexedSeqOptimized$class.head(IndexedSeqOptimized.scala:120)
at scala.collection.mutable.WrappedArray.head(WrappedArray.scala:34)
at org.apache.spark.mllib.recommendation.MatrixFactorizationModel.recommendProducts(MatrixFactorizationModel.scala:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)
at py4j.Gateway.invoke(Gateway.java:259)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:207)
at java.lang.Thread.run(Thread.java:745)
如您在上面的第一行中所见,我正在跑步
As you can see in first line above, I am running
user_products = model.call("recommendProducts", user, prodNum)
代替
user_products = model.recommendProducts(user, prodNum)
因为后者未在我使用的1.3.0 pyspark中实现. 无论如何,它正确地为某些用户返回了预测,但随后对其他用户却失败了.
because the latter is not implemented in 1.3.0 pyspark which I am using. Anyhow, it correctly returns prediction for some users, but then it fails on others.
我知道它可能没有我要求的确切预测数,我希望它返回的数会更少.
I understand that it probably does not have the exact number of predictions I am requesting, I would expect it would return fewer.
推荐答案
简短答案:
- 您已经针对用户ID在[0; N]范围内的评级训练了模型
- 您已要求提供有关userID = N + x的建议,其中x是正整数.这引起了异常.
其余的答案:
- 您可以在培训阶段使用的userID空间内提出建议
- 您可以提出与培训阶段使用的产品空间一样多的建议
当您要向新用户推荐时,必须将有关他或她的品味的信息添加到训练数据集中.
When you want to make recommendation for a new user you have to add information about his or her taste to a training dataset.
您可以在 Spark Summit 2014之手中找到有关协作过滤的示例练习.
(如果我错过了任何事情,请在下面的评论中纠正我)
这篇关于MLlib MatrixFactorizationModel RecommendationProducts(user,num)在某些用户上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!