\负荷模型我使用PySpark和MLlib星火1.3.0工作的正确方法,我需要保存和载入我的模型。我用这样的代码(来自官方documentation拍摄)什么是保存在星火 PySpark
from pyspark.mllib.recommendation import ALS, MatrixFactorizationModel, Rating
data = sc.textFile("data/mllib/als/test.data")
ratings = data.map(lambda l: l.split(',')).map(lambda l: Rating(int(l[0]), int(l[1]), float(l[2])))
rank = 10
numIterations = 20
model = ALS.train(ratings, rank, numIterations)
testdata = ratings.map(lambda p: (p[0], p[1]))
predictions = model.predictAll(testdata).map(lambda r: ((r[0], r[1]), r[2]))
predictions.collect() # shows me some predictions
model.save(sc, "model0")
# Trying to load saved model and work with it
model0 = MatrixFactorizationModel.load(sc, "model0")
predictions0 = model0.predictAll(testdata).map(lambda r: ((r[0], r[1]), r[2]))
后,我尝试使用model0我得到一个长回溯,这只能到此为止:
Py4JError: An error occurred while calling o70.predict. Trace:
py4j.Py4JException: Method predict([class org.apache.spark.api.java.JavaRDD]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:333)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:342)
at py4j.Gateway.invoke(Gateway.java:252)
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)
所以我的问题是 - 我是做错了什么?据我调试,我的模型存储(本地和HDFS),他们包含许多文件与一些数据。我有一种感觉,模型保存正确,但可能他们没有正确加载。我也搜索了一下,但没有发现任何相关信息。
貌似这个保存\加载功能已被添加在最近因为这个星火1.3.0,我有另外一个问题 - 什么是推荐的方式发布1.3.0之前保存\负荷模型?我还没有找到任何好的方法来做到这一点,至少对于Python来说。我也试过味酸,但面临着同样的问题,这里描述Save Apache Spark mllib model in python
十分感谢!看起来像这是一个Python绑定只有bug .. – artemdevel 2015-03-30 08:53:31