我正在使用 spark 版本在 pyspark 中运行逻辑回归:2.1.2
我知道可以按如下方式保存回归模型:
# Initialise the logistic regression
model = LogisticRegression(featuresCol='features', labelCol='is_clickout',regParam=0, fitIntercept=False, family="binomial")
model = pipeline.fit(data)
# save model for future use
save_path = "model_0"
model.save(save_path)
问题是保存的模型没有保存摘要:
from pyspark.ml.classification import LogisticRegressionModel
model2 = LogisticRegressionModel.load(save_path)
model2.hasSummary ##### Returns FALSE
我可以按如下方式提取摘要,但它没有附加保存方法:
# 获取模型摘要
摘要 = model.stages[-1].summary
有没有一种快速的方法来保存摘要对象?对于多元回归?
目前我读取了对象的所有属性并将其保存为pandas df。
最佳答案
不幸的是,您的观察是正确的。我在 Spark 2.4.3 上遇到了同样的问题,我发现 this comment确认问题:
For LinearRegressionModel, this does NOT currently save the training summary. An option to save summary may be added in the future.
同样的评论仍然存在于 Spark 3.0.0-rc1(其存储库中的最后一个可用标签)。
如果我们想持久化 摘要 ,我们需要自己以某种方式序列化它。我之前通过提取我想要的统计数据并将它们保存在 JSON 文档中,在训练我的模型之后完成了此操作。
关于python - 保存 Spark 模型摘要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53722410/