Scala Python Java Other
Clone or download
Failed to load latest commit information.
bundle-ml [Ready For Merge] Spark 2.3 Support (#364) May 18, 2018
bundle-protobuf @ 83b3ff7 Allow for arbitrary metadata to be encoded into a bundle (#334) Feb 20, 2018
examples update spark and scikit-learn examples in readme(s) (#255) Sep 7, 2017
mleap-avro Refactor LeapFrame to make a consistent interface (#286) Oct 9, 2017
mleap-base Refactor LeapFrame to make a consistent interface (#286) Oct 9, 2017
mleap-benchmark Refactor LeapFrame to make a consistent interface (#286) Oct 9, 2017
mleap-core Mleap-386 fixing BinaryLogisticRegression predictions (#387) Aug 2, 2018
mleap-runtime Fix "Failed to find a default value for link" error for GeneralizedLi… Jun 6, 2018
mleap-serving MLeap Serving Parameters (#366) May 21, 2018
mleap-spark-base Fix getVectorSize in spark TypeConverters (#394) Aug 10, 2018
mleap-spark-extension [Ready For Merge] Spark 2.3 Support (#364) May 18, 2018
mleap-spark-testkit Mark provided testkit datasets as lazy, preventing their loading if n… May 18, 2018
mleap-spark Mleap-386 fixing BinaryLogisticRegression predictions (#387) Aug 2, 2018
mleap-tensor Fix up some Spark bundle ops and make parity specs more flexible (#263) Sep 21, 2017
mleap-tensorflow tensorflow spec (#358) Apr 4, 2018
mleap-xgboost-java Refactor LeapFrame to make a consistent interface (#286) Oct 9, 2017
mleap-xgboost-spark [Ready For Merge] Spark 2.3 Support (#364) May 18, 2018
project [Ready For Merge] Spark 2.3 Support (#364) May 18, 2018
python removed non-existing import (#385) Aug 2, 2018
travis Update "/transform" path in mleap-serving module to only accept POST … Mar 9, 2017
vendor XGBoost Integration (#259) Sep 23, 2017
.gitignore PySpark Bindings for Serialization and Deserialization (#31) Nov 6, 2016
.gitmodules XGBoost Integration (#259) Sep 23, 2017
.travis.yml Merge MLeap<>Scikit Integration into master (#199) Apr 27, 2017
LICENSE Update LICENSE and Sep 29, 2016
NOTICE XGBoost Integration (#259) Sep 23, 2017 Fix spelling (#388) Aug 2, 2018
build.sbt Finish backing out of doge changes. Sep 25, 2017
logo.png Include logo in Jan 20, 2017
version.sbt Setting version to 0.11.0-SNAPSHOT Aug 6, 2018

MLeap Logo

Gitter Build Status Maven Central

Deploying machine learning data pipelines and algorithms should not be a time-consuming or difficult task. MLeap allows data scientists and engineers to deploy machine learning pipelines from Spark and Scikit-learn to a portable format and execution engine.


Documentation is available at

Read Serializing a Spark ML Pipeline and Scoring with MLeap to gain a full sense of what is possible.


Using the MLeap execution engine and serialization format, we provide a performant, portable and easy-to-integrate production library for machine learning data pipelines and algorithms.

For portability, we build our software on the JVM and only use serialization formats that are widely-adopted.

We also provide a high level of integration with existing technologies.

Our goals for this project are:

  1. Allow Researchers/Data Scientists and Engineers to continue to build data pipelines and train algorithms with Spark and Scikit-Learn
  2. Extend Spark/Scikit/TensorFlow by providing ML Pipelines serialization/deserialization to/from a common framework (Bundle.ML)
  3. Use MLeap Runtime to execute your pipeline and algorithm without dependenices on Spark or Scikit (numpy, pandas, etc)


  1. Core execution engine implemented in Scala
  2. Spark, PySpark and Scikit-Learn support
  3. Export a model with Scikit-learn or Spark and execute it using the MLeap Runtime (without dependencies on the Spark Context, or sklearn/numpy/pandas/etc)
  4. Choose from 2 portable serialization formats (JSON, Protobuf)
  5. Implement your own custom data types and transformers for use with MLeap data frames and transformer pipelines
  6. Extensive test coverage with full parity tests for Spark and MLeap pipelines
  7. Optional Spark transformer extension to extend Spark's default transformer offerings

Unified Runtime


MLeap is built against Scala 2.11 and Java 8. Because we depend heavily on Typesafe config for MLeap, we only support Java 8 at the moment.


Link with Maven or SBT


libraryDependencies += "ml.combust.mleap" %% "mleap-runtime" % "0.10.0"



For Spark Integration


libraryDependencies += "ml.combust.mleap" %% "mleap-spark" % "0.10.0"



Spark Packages

$ bin/spark-shell --packages ml.combust.mleap:mleap-spark_2.11:0.10.0

PySpark Integration

Install MLeap from pypy

$ pip install mleap

Using the Library

For more complete examples, see our other Git repository: MLeap Demos

Create and Export a Spark Pipeline

The first step is to create our pipeline in Spark. For our example we will manually build a simple Spark ML pipeline.

import ml.combust.bundle.BundleFile
import ml.combust.mleap.spark.SparkSupport._
import{Binarizer, StringIndexer}
import org.apache.spark.sql._
import org.apache.spark.sql.functions._
import resource._

  val datasetName = "./examples/spark-demo.csv"

  val dataframe: DataFrame ="csv")
    .option("header", true)
    .withColumn("test_double", col("test_double").cast("double"))

  // User out-of-the-box Spark transformers like you normally would
  val stringIndexer = new StringIndexer().

  val binarizer = new Binarizer().

  val pipelineEstimator = new Pipeline()
    .setStages(Array(stringIndexer, binarizer))

  val pipeline =

  // then serialize pipeline
  val sbc = SparkBundleContext().withDataset(pipeline.transform(dataframe))
  for(bf <- managed(BundleFile("jar:file:/tmp/"))) {

The dataset used for training can be found here

Spark pipelines are not meant to be run outside of Spark. They require a DataFrame and therefore a SparkContext to run. These are expensive data structures and libraries to include in a project. With MLeap, there is no dependency on Spark to execute a pipeline. MLeap dependencies are lightweight and we use fast data structures to execute your ML pipelines.

PySpark Integration

Import the MLeap library in your PySpark job

import mleap.pyspark
from mleap.pyspark.spark_support import SimpleSparkSerializer

Create and Export a Scikit-Learn Pipeline

import pandas as pd

from mleap.sklearn.pipeline import Pipeline
from import FeatureExtractor, LabelEncoder, ReshapeArrayToN1
from sklearn.preprocessing import OneHotEncoder

data = pd.DataFrame(['a', 'b', 'c'], columns=['col_a'])

categorical_features = ['col_a']

feature_extractor_tf = FeatureExtractor(input_scalars=categorical_features, 

# Label Encoder for x1 Label 
label_encoder_tf = LabelEncoder(input_features=feature_extractor_tf.output_vector_items,

# Reshape the output of the LabelEncoder to N-by-1 array
reshape_le_tf = ReshapeArrayToN1()

# Vector Assembler for x1 One Hot Encoder
one_hot_encoder_tf = OneHotEncoder(sparse=False)
one_hot_encoder_tf.mlinit(prior_tf = label_encoder_tf, 
                          output_features = '{}_label_one_hot_encoded'.format(categorical_features[0]))

one_hot_encoder_pipeline_x0 = Pipeline([
                                         (, feature_extractor_tf),
                                         (, label_encoder_tf),
                                         (, reshape_le_tf),
                                         (, one_hot_encoder_tf)

one_hot_encoder_pipeline_x0.serialize_to_bundle('/tmp', 'mleap-scikit-test-pipeline', init=True)

# array([[ 1.,  0.,  0.],
#        [ 0.,  1.,  0.],
#        [ 0.,  0.,  1.]])

Load and Transform Using MLeap

Because we export Spark and Scikit-learn pipelines to a standard format, we can use either our Spark-trained pipeline or our Scikit-learn pipeline from the previous steps to demonstrate usage of MLeap in this section. The choice is yours!

import ml.combust.bundle.BundleFile
import ml.combust.mleap.runtime.MleapSupport._
import resource._
// load the Spark pipeline we saved in the previous section
val bundle = (for(bundleFile <- managed(BundleFile("jar:file:/tmp/"))) yield {

// create a simple LeapFrame to transform
import ml.combust.mleap.runtime.frame.{DefaultLeapFrame, Row}
import ml.combust.mleap.core.types._

// MLeap makes extensive use of monadic types like Try
val schema = StructType(StructField("test_string", ScalarType.String),
  StructField("test_double", ScalarType.Double)).get
val data = Seq(Row("hello", 0.6), Row("MLeap", 0.2))
val frame = DefaultLeapFrame(schema, data)

// transform the dataframe using our pipeline
val mleapPipeline = bundle.root
val frame2 = mleapPipeline.transform(frame).get
val data2 = frame2.dataset

// get data from the transformed rows and make some assertions
assert(data2(0).getDouble(2) == 1.0) // string indexer output
assert(data2(0).getDouble(3) == 1.0) // binarizer output

// the second row
assert(data2(1).getDouble(2) == 2.0)
assert(data2(1).getDouble(3) == 0.0)


For more documentation, please see our documentation, where you can learn to:

  1. Implement custom transformers that will work with Spark, MLeap and Scikit-learn
  2. Implement custom data types to transform with Spark and MLeap pipelines
  3. Transform with blazing fast speeds using optimized row-based transformers
  4. Serialize MLeap data frames to various formats like avro, json, and a custom binary format
  5. Implement new serialization formats for MLeap data frames
  6. Work through several demonstration pipelines which use real-world data to create predictive pipelines
  7. Supported Spark transformers
  8. Supported Scikit-learn transformers
  9. Custom transformers provided by MLeap


  • Write documentation.
  • Write a tutorial/walkthrough for an interesting ML problem
  • Contribute an Estimator/Transformer from Spark
  • Use MLeap at your company and tell us what you think
  • Make a feature request or report a bug in github
  • Make a pull request for an existing feature request or bug report
  • Join the discussion of how to get MLeap into Spark as a dependency. Talk with us on Gitter (see link at top of

Thank You

Thank you to Swoop for supporting the XGboost integration.

Contact Information


See LICENSE and NOTICE file in this repository.

Copyright 2016 Combust, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.