Java library and command-line application for converting Apache Spark ML pipelines to PMML.
- Supported Spark ML
PipelineStagetypes:- Feature extractors, transformers and selectors:
feature.Binarizerfeature.Bucketizerfeature.ChiSqSelectorModel(the result of fitting afeature.ChiSqSelector)feature.ColumnPrunerfeature.CountVectorizerModel(the result of fitting afeature.CountVectorizer)feature.IDFModel(the result of fitting afeature.IDF)feature.ImputerModel(the result of fitting afeature.Imputer)feature.IndexToStringfeature.Interactionfeature.MaxAbsScalerModel(the result of fitting afeature.MaxAbsScaler)feature.MinMaxScalerModel(the result of fitting afeature.MinMaxScaler)feature.NGramfeature.OneHotEncoderfeature.OneHotEncoderModel(the result of fitting afeature.OneHotEncoderEstimator)feature.PCAModel(the result of fitting afeature.PCA)feature.QuantileDiscretizerfeature.RegexTokenizerfeature.RFormulaModel(the result of fitting afeature.RFormula)feature.SQLTransformerfeature.StandardScalerModel(the result of fitting afeature.StandardScaler)feature.StopWordsRemoverfeature.StringIndexerModel(the result of fitting afeature.StringIndexer)feature.Tokenizerfeature.VectorAssemblerfeature.VectorAttributeRewriterfeature.VectorIndexerModel(the result of fitting afeature.VectorIndexer)feature.VectorSizeHintfeature.VectorSlicer
- Prediction models:
classification.DecisionTreeClassificationModelclassification.GBTClassificationModelclassification.LinearSVCModelclassification.LogisticRegressionModelclassification.MultilayerPerceptronClassificationModelclassification.NaiveBayesModelclassification.RandomForestClassificationModelclustering.KMeansModelregression.DecisionTreeRegressionModelregression.GBTRegressionModelregression.GeneralizedLinearRegressionModelregression.LinearRegressionModelregression.RandomForestRegressionModel
- Prediction model chains:
PipelineModel- Referencing the prediction column (
HasPredictionCol#getPredictionCol()) of earlier clustering, classification and regression models. - Referencing the predicted probabilities column (
HasProbabilityCol#getProbabilityCol()) of earlier classification models.
- Hyperparameter selectors and tuners:
- Feature extractors, transformers and selectors:
- Production quality:
- Complete test coverage.
- Fully compliant with the JPMML-Evaluator library.
- Apache Spark version 1.5.X, 1.6.X, 2.0.X, 2.1.X, 2.2.X, 2.3.X or 2.4.X.
JPMML-SparkML library JAR file (together with accompanying Java source and Javadocs JAR files) is released via Maven Central Repository.
The current version is 1.5.2 (7 April, 2019).
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>jpmml-sparkml</artifactId>
<version>1.5.2</version>
</dependency>Compatibility matrix:
| Apache Spark version | JPMML-SparkML branch | Status |
|---|---|---|
| 1.5.X and 1.6.X | 1.0.X |
Archived |
| 2.0.X | 1.1.X |
Archived |
| 2.1.X | 1.2.X |
Archived |
| 2.2.X | 1.3.X |
Active |
| 2.3.X | 1.4.X |
Active |
| 2.4.X | master |
Active |
JPMML-SparkML depends on the latest and greatest version of the JPMML-Model library, which is in conflict with the legacy version that is part of Apache Spark version 2.0.X, 2.1.X and 2.2.X distributions.
This conflict is documented in SPARK-15526. For possible resolutions, please switch from this README.md file to the README.md file of some earlier JPMML-SparkML development branch.
Enter the project root directory and build using Apache Maven:
mvn clean install
The build produces two JAR files:
target/jpmml-sparkml-1.5-SNAPSHOT.jar- Library JAR file.target/jpmml-sparkml-executable-1.5-SNAPSHOT.jar- Example application JAR file.
Fitting a Spark ML pipeline that only makes use of supported Transformer types:
DataFrame irisData = ...;
StructType schema = irisData.schema();
RFormula formula = new RFormula()
.setFormula("Species ~ .");
DecisionTreeClassifier classifier = new DecisionTreeClassifier()
.setLabelCol(formula.getLabelCol())
.setFeaturesCol(formula.getFeaturesCol());
Pipeline pipeline = new Pipeline()
.setStages(new PipelineStage[]{formula, classifier});
PipelineModel pipelineModel = pipeline.fit(irisData);Converting the Spark ML pipeline to PMML using the org.jpmml.sparkml.PMMLBuilder builder class:
PMML pmml = new PMMLBuilder(schema, pipelineModel)
.build();
// Viewing the result
JAXBUtil.marshalPMML(pmml, new StreamResult(System.out));Please refer to the following resources for more ideas and code examples:
The example application JAR file contains an executable class org.jpmml.sparkml.Main, which can be used to convert a pair of serialized org.apache.spark.sql.types.StructType and org.apache.spark.ml.PipelineModel objects to PMML.
The example application JAR file does not include Apache Spark runtime libraries. Therefore, this executable class must be executed using Apache Spark's spark-submit helper script.
For example, converting a pair of Spark ML schema and pipeline serialization files src/test/resources/schema/Iris.json and src/test/resources/pipeline/DecisionTreeIris.zip, respectively, to a PMML file DecisionTreeIris.pmml:
spark-submit --master local --class org.jpmml.sparkml.Main target/jpmml-sparkml-executable-1.5-SNAPSHOT.jar --schema-input src/test/resources/schema/Iris.json --pipeline-input src/test/resources/pipeline/DecisionTreeIris.zip --pmml-output DecisionTreeIris.pmml
Getting help:
spark-submit --master local --class org.jpmml.sparkml.Main target/jpmml-sparkml-executable-1.5-SNAPSHOT.jar --help
JPMML-SparkML is dual-licensed under the GNU Affero General Public License (AGPL) version 3.0, and a commercial license.
JPMML-SparkML is developed and maintained by Openscoring Ltd, Estonia.
Interested in using JPMML software in your application? Please contact [email protected]