如何在PySpark 1.4.2中保存线性回归模型?

时间:2018-03-12 18:53:32

标签: python machine-learning pyspark apache-spark-mllib pyspark-sql

我正在尝试在PySpark 1.4.2中保存模型。但低于错误

model.save(sc, modelpath)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'LinearRegressionModel' object has no attribute 'save'
你可以让我知道我哪里出错吗?即使在Apache Spark 1.4.1 example

中也无法弄明白

以下是我的代码,

>>> from pyspark.mllib.linalg import Vectors
>>> df = sqlContext.createDataFrame([
...     (1.0, Vectors.dense(1.0)),
...     (0.0, Vectors.sparse(1, [], []))], ["label", "features"])
>>> lr = LinearRegression(maxIter=5, regParam=0.0)
>>> model = lr.fit(df)
>>> model.transform(test0).head().prediction
-1.0
>>> model.weights
DenseVector([1.0])
>>> model.intercept
0.0
>>> model.save("path")
>>>model.save(sc, modelpath) --tried both got same error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'LinearRegressionModel' object has no attribute 'save'
>>> modl = LinearRegression.load(path)

最后2行不起作用。

0 个答案:

没有答案