\負荷模型我使用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