• Stars
    star
    265
  • Rank 154,577 (Top 4 %)
  • Language
    Java
  • License
    GNU Affero Genera...
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

JPMML-SparkML Build Status

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

Table of Contents

Features

Overview

  • Functionality:
    • Thorough collection, analysis and encoding of feature information:
      • Names.
      • Data and operational types.
      • Valid, invalid and missing value spaces.
    • Pipeline extensions:
      • Pruning.
      • Model verification.
    • Conversion options.
  • Extensibility:
    • Rich Java APIs for developing custom converters.
    • Automatic discovery and registration of custom converters based on META-INF/sparkml2pmml.properties resource files.
    • Direct interfacing with other JPMML conversion libraries such as JPMML-LightGBM and JPMML-XGBoost.
  • Production quality:
    • Complete test coverage.
    • Fully compliant with the JPMML-Evaluator library.

Supported libraries

Apache Spark ML
LightGBM
XGBoost

Prerequisites

  • Apache Spark 3.0.X, 3.1.X, 3.2.X, 3.3.X or 3.4.X.

Installation

Library

JPMML-SparkML library JAR file (together with accompanying Java source and Javadocs JAR files) is released via Maven Central Repository.

The current version is 2.4.0 (27 April, 2023).

<dependency>
	<groupId>org.jpmml</groupId>
	<artifactId>pmml-sparkml</artifactId>
	<version>2.4.0</version>
</dependency>

Compatibility matrix

Active development branches:

Apache Spark version JPMML-SparkML branch
3.0.X 2.0.X
3.1.X 2.1.X
3.2.X 2.2.X
3.3.X 2.3.X
3.4.X master

Archived development branches:

Apache Spark version JPMML-SparkML branch
1.5.X and 1.6.X 1.0.X
2.0.X 1.1.X
2.1.X 1.2.X
2.2.X 1.3.X
2.3.X 1.4.X
2.4.X 1.5.X
3.0.X 1.6.X
3.1.X 1.7.X
3.2.X 1.8.X

Example application

Enter the project root directory and build using Apache Maven:

mvn clean install

The build produces two JAR files:

  • pmml-sparkml/target/pmml-sparkml-2.4-SNAPSHOT.jar - Library JAR file.
  • pmml-sparkml-exampletarget/pmml-sparkml-example-executable-2.4-SNAPSHOT.jar - Example application JAR file.

Usage

Library

Fitting a Spark ML pipeline:

import org.apache.spark.ml.Pipeline
import org.apache.spark.ml.classification.DecisionTreeClassifier
import org.apache.spark.ml.feature.RFormula

val irisData = spark.read.format("csv").option("header", "true").option("inferSchema", "true").load("Iris.csv")
val irisSchema = irisData.schema

val rFormula = new RFormula().setFormula("Species ~ .")
val dtClassifier = new DecisionTreeClassifier().setLabelCol(rFormula.getLabelCol).setFeaturesCol(rFormula.getFeaturesCol)
val pipeline = new Pipeline().setStages(Array(rFormula, dtClassifier))

val pipelineModel = pipeline.fit(irisData)

Converting the fitted Spark ML pipeline to an in-memory PMML class model object:

import org.jpmml.sparkml.PMMLBuilder

val pmml = new PMMLBuilder(irisSchema, pipelineModel).build()

The representation of individual Spark ML pipeline stages can be customized via conversion options:

import org.jpmml.sparkml.PMMLBuilder
import org.jpmml.sparkml.model.HasTreeOptions

val dtClassifierModel = pipelineModel.stages(1)

val pmml = new PMMLBuilder(irisSchema, pipelineModel).putOption(dtClassifierModel, HasTreeOptions.OPTION_COMPACT, false).putOption(dtClassifierModel, HasTreeOptions.OPTION_ESTIMATE_FEATURE_IMPORTANCES, true).build()

Viewing the in-memory PMML class model object:

import javax.xml.transform.stream.StreamResult
import org.jpmml.model.JAXBUtil

JAXBUtil.marshalPMML(pmml, new StreamResult(System.out))

Example application

The example application JAR file contains an executable class org.jpmml.sparkml.example.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 pmml-sparkml/src/test/resources/schema/Iris.json and pmml-sparkml/src/test/resources/pipeline/DecisionTreeIris.zip, respectively, to a PMML file DecisionTreeIris.pmml:

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

Getting help:

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

Documentation

License

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]

More Repositories

1

jpmml-evaluator

Java Evaluator API for PMML
Java
864
star
2

sklearn2pmml

Python library for converting Scikit-Learn pipelines to PMML
Python
666
star
3

jpmml-sklearn

Java library and command-line application for converting Scikit-Learn pipelines to PMML
Java
517
star
4

jpmml-lightgbm

Java library and command-line application for converting LightGBM models to PMML
Java
160
star
5

jpmml-model

Java Class Model API for PMML
Java
147
star
6

jpmml-xgboost

Java library and command-line application for converting XGBoost models to PMML
Java
122
star
7

jpmml-evaluator-spark

PMML evaluator library for the Apache Spark cluster computing system (http://spark.apache.org/)
Java
94
star
8

pyspark2pmml

Python library for converting Apache Spark ML pipelines to PMML
Python
92
star
9

jpmml

Java PMML API (legacy codebase)
Java
81
star
10

jpmml-tensorflow

Java library and command-line application for converting TensorFlow models to PMML
Java
75
star
11

r2pmml

R library for converting R models to PMML
R
71
star
12

jpmml-sparkml-xgboost

JPMML-SparkML plugin for converting XGBoost4J-Spark models to PMML
Java
36
star
13

jpmml-r

Java library and command-line application for converting R models to PMML
Java
32
star
14

jpmml-android

PMML evaluator library for the Android operating system (http://www.android.com/)
Java
27
star
15

jpmml-transpiler

Java Transpiler (Translator + Compiler) API for PMML
Java
23
star
16

jpmml-h2o

Java library and command-line application for converting H2O.ai models to PMML
Java
20
star
17

sklearn2pmml-plugin

The simplest way to extend sklearn2pmml package with custom transformation and model types
Java
19
star
18

jpmml-evaluator-python

PMML evaluator library for Python
Python
19
star
19

jpmml-converter

Java library for authoring PMML
Java
15
star
20

jpmml-cascading

PMML evaluator library for the Cascading application framework (http://www.cascading.org/)
Java
13
star
21

jpmml-hive

PMML evaluator library for the Apache Hive data warehouse software (legacy codebase)
Java
13
star
22

jpmml-postgresql

PMML evaluator library for the PostgreSQL database (http://www.postgresql.org/)
Java
11
star
23

jpmml-catboost

Java library and command-line application for converting CatBoost models to PMML
Java
7
star
24

jpmml-evaluator-hive

PMML evaluator library for the Apache Hive data warehouse software (http://hive.apache.org/)
Java
6
star
25

sparklyr2pmml

R library for converting Apache Spark ML pipelines to PMML
R
6
star
26

jpmml-statsmodels

Java library and command-line application for converting StatsModels models to PMML
Java
5
star
27

jpmml-storm

PMML evaluator library for the Apache Storm distributed realtime computation system (https://storm.apache.org/)
Java
5
star
28

jpmml-pig

PMML evaluator library for the Apache Pig platform (legacy codebase)
Java
4
star
29

jpmml-sparkml-bootstrap

The simplest way to get started with a JPMML-SparkML powered software project (legacy codebase)
Java
3
star
30

jpmml-python

Java library for converting Python models to PMML
Java
3
star
31

jpmml-example

Example JPMML-enabled software development project (legacy codebase)
Java
2
star
32

jpmml-codevault

Java utilities for protecting Java application code
Java
1
star
33

jpmml-codemodel

Java utilities for generating, compiling and packaging Java application code
Java
1
star