管道拟合后如何保存模型?
How to save the model after doing pipeline fit?
我用 Spark ML 写了这段代码
import org.apache.spark.ml.classification.LogisticRegression
import org.apache.spark.ml.Pipeline
val lr = new LogisticRegression()
val pipeline = new Pipeline()
.setStages(Array(fooIndexer, fooHotEncoder, assembler, lr))
val model = pipeline.fit(training)
此代码需要很长时间才能 运行。在 运行ning pipeline.fit 之后,我是否可以将模型保存在 HDFS 上,这样我就不必一次又一次地 运行 了?
编辑:此外,当我必须在模型上应用 transform
以便我可以做出预测时,如何从 HDFS 加载它。
直接来自 official documentation - 节省:
// Now we can optionally save the fitted pipeline to disk
model.write.overwrite().save("/tmp/spark-logistic-regression-model")
正在加载:
// And load it back in during production
val sameModel = PipelineModel.load("/tmp/spark-logistic-regression-model")
相关:
我用 Spark ML 写了这段代码
import org.apache.spark.ml.classification.LogisticRegression
import org.apache.spark.ml.Pipeline
val lr = new LogisticRegression()
val pipeline = new Pipeline()
.setStages(Array(fooIndexer, fooHotEncoder, assembler, lr))
val model = pipeline.fit(training)
此代码需要很长时间才能 运行。在 运行ning pipeline.fit 之后,我是否可以将模型保存在 HDFS 上,这样我就不必一次又一次地 运行 了?
编辑:此外,当我必须在模型上应用 transform
以便我可以做出预测时,如何从 HDFS 加载它。
直接来自 official documentation - 节省:
// Now we can optionally save the fitted pipeline to disk model.write.overwrite().save("/tmp/spark-logistic-regression-model")
正在加载:
// And load it back in during production val sameModel = PipelineModel.load("/tmp/spark-logistic-regression-model")
相关: