MLeap Python API
Actively maintained. Last release 3 weeks ago, commits in 4 of the last 26 weeks. A safe choice.
pip install mleapPython integration package for MLeap
This package contains libraries to integrate MLeap with:
- PySpark
- Scikit-Learn
- gensim (optional, Word2Vec serialization)
- TensorFlow (coming soon)
Installation
$ pip install mleap
PySpark Integration
MLeap's PySpark library provides serialization and deserialization functionality to/from Bundle.ML. There is 100% parity between MLeap's PySpark and Scala/Spark support and all of the supported transformers can be found here.
We have both a basic tutorial and an advance demo of serializing and de-serializing using PySpark, but in short you can continue to write ML Pipelines as you normally would and we provide the following interface for serialization/de-serialization:
# Define your pipeline
feature_pipeline = [string_indexer, feature_assembler]
featurePipeline = Pipeline(stages=feature_pipeline)
# Fit your pipeline
fittedPipeline = featurePipeline.fit(df)
# Serialize your pipeline
fittedPipeline.serializeToBundle("jar:file:/tmp/pyspark.example.zip", fittedPipeline.transform(df))
StringMap transformer
# dict of label mappings
labels = {'a': 1.0}
string_map_transformer = StringMap(
labels, 'key_col', 'value_col', handleInvalid='keep', defaultValue=0.0)
MathUnary transformer
Example usage:
# dict of label mappings
input_dataframe = pd.DataFrame([[0.1, 0.2, 0.3]], columns=['f1'])
sin_transformer = MathUnary(
operation=UnaryOperation.Sin,
inputCol="f1",
outputCol="sin(f1)",
)
sin_transformer.transform(input_dataframe)
Scikit-Learn Integration
MLeap's Scikit-Learn library provides serialization (de-serialization coming soon) functionality to Bundle.ML. There is already parity between the math that Scikit and Spark transformers execute, and MLeap takes advantage of that to provide a common serialization format for the two technologies.
A simple example is the StandardScaler transformer that normalizes the data given the mean and standard deviation. Both Spark and Scikit perform the standard normal transform on the data, and can both be serialized to the following format: