Spark 2.0 comes with the ability to save and load machine learning models across programming languages with ease. In other words, you can create a machine learning model in Scala and load it in Python. This allows us to create a model in one system, save it, copy it, and use it in other systems. Continuing with the same Scala REPL prompt, try the following statements:
scala> // Assuming that the model definition line "val model =
lr.fit(trainingDF)" is still in context
scala> import org.apache.spark.ml.regression.LinearRegressionModel
import org.apache.spark.ml.regression.LinearRegressionModel
scala> model.save("wineLRModelPath")
scala> val newModel = LinearRegressionModel.load("wineLRModelPath")
newModel: org.apache.spark.ml.regression.LinearRegressionModel =
linReg_6a880215ab96
Now the loaded model can be used for testing or prediction, just like the original model. Continuing with the same Python REPL prompt, try...