Java library and command-line application for converting Apache Spark ML pipelines to PMML.

Table of Contents





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.6.1 (23 June, 2020).


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 Archived
2.3.X 1.4.X Active
2.4.X 1.5.X Active
3.0.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 file to the file of some earlier JPMML-SparkML development branch.

Example application

Enter the project root directory and build using Apache Maven:

mvn clean install

The build produces two JAR files:



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()

Pipeline pipeline = new Pipeline()
    .setStages(new PipelineStage[]{formula, classifier});

PipelineModel pipelineModel =;

Converting the Spark ML pipeline to PMML using the org.jpmml.sparkml.PMMLBuilder builder class:

PMML pmml = new PMMLBuilder(schema, pipelineModel)

// Viewing the result
JAXBUtil.marshalPMML(pmml, new StreamResult(System.out));

Example application

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 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/, respectively, to a PMML file DecisionTreeIris.pmml:

spark-submit --master local --class org.jpmml.sparkml.Main target/jpmml-sparkml-executable-1.6-SNAPSHOT.jar --schema-input src/test/resources/schema/Iris.json --pipeline-input src/test/resources/pipeline/ --pmml-output DecisionTreeIris.pmml

Getting help:

spark-submit --master local --class org.jpmml.sparkml.Main target/jpmml-sparkml-executable-1.6-SNAPSHOT.jar --help



JPMML-SparkML is licensed under the terms and conditions of the GNU Affero General Public License, Version 3.0.

If you would like to use JPMML-SparkML in a proprietary software project, then it is possible to enter into a licensing agreement which makes JPMML-SparkML available under the terms and conditions of the BSD 3-Clause License instead.

Additional information

JPMML-SparkML is developed and maintained by Openscoring Ltd, Estonia.

Interested in using Java PMML API software in your company? Please contact [email protected]