I would like to use MLeap to deploy Spark ML machine learning models and use them to predict in real-time.
The creators put out a Scala tutorial, but I need to support a Java 8 codebase.
How would I implement the following code in Java 8:
val pipeline = SparkUtil.createPipelineModel(uid = "pipeline", Array(featureModel, rfModel))
val sbc = SparkBundleContext()
for(bf <- managed(BundleFile("jar:file:/tmp/mnist.model.rf.zip"))) {
pipeline.writeBundle.save(bf)(sbc).get
}
val bundle = (for(bundleFile <- managed(BundleFile("jar:file:/tmp/simple-spark-pipeline.zip"))) yield {
bundleFile.loadMleapBundle().get
}).opt.get
If you are using plain Spark ML transformers only, you can use the SimpleSparkSerializer to easily save and load your models.
Saving:
new SimpleSparkSerializer().serializeToBundle(model, "jar:file:/tmp/model.zip", trainData);
Loading:
Transformer model = new SimpleSparkSerializer().deserializeFromBundle("jar:file:/tmp/model.zip");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With