Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala to Java 8 MLeap Translation

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
like image 225
MiketheViking90 Avatar asked Dec 12 '25 03:12

MiketheViking90


1 Answers

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");
like image 72
user8337450 Avatar answered Dec 13 '25 19:12

user8337450



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!