• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    Java
  • License
    BSD 3-Clause "New...
  • Created over 10 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

Java Class Model API for PMML

JPMML-Model Build Status

Java Class Model API for Predictive Model Markup Language (PMML).

Features

  • Full support for PMML 3.0, 3.1, 3.2, 4.0, 4.1, 4.2, 4.3 and 4.4 schemas:
    • Schema version annotations.
    • Extension elements, attributes, enum values.
  • Enhanced API:
    • Class hierarchy.
    • Marker interfaces for common traits.
    • Value constructors.
    • Method chaining-friendly setter methods.
    • Optional SAX Locator information.
  • Visitor pattern:
    • Validation agents.
    • Optimization and transformation agents.
  • Supported platforms:
    • Java SE and EE.
    • Android.
    • Google Web Toolkit (GWT).
  • Supported JAXB runtimes:
  • Supported SerDe runtimes:

Prerequisites

  • Java 1.8 or newer.

Installation

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

The current version is 1.6.4 (1 August, 2022).

<dependency>
	<groupId>org.jpmml</groupId>
	<artifactId>pmml-model</artifactId>
	<version>1.6.4</version>
</dependency>

Usage

The class model consists of two types of classes. There is a small number of manually crafted classes that are used for structuring the class hierarchy. They are permanently stored in the Java sources directory /pmml-model/src/main/java. Additionally, there is a much greater number of automatically generated classes that represent actual PMML elements. They can be found in the generated Java sources directory /pmml-model/target/generated-sources/xjc after a successful build operation.

All class model classes descend from class org.dmg.pmml.PMMLObject. Additional class hierarchy levels, if any, represent common behaviour and/or features. For example, all model classes descend from class org.dmg.pmml.Model.

The class model should be self-explanatory. The application developer is advised to consult with the latest PMML specification about the specifics of individual PMML elements and attributes.

Unmarshalling

Loading any PMML schema version 3.X or 4.X document into live org.dmg.pmml.PMML instance:

public PMML load(InputStream is) throws SAXException, JAXBException {
  return org.jpmml.model.PMMLUtil.unmarshal(is);
}

Important: It is the responsibility of the application developer to ensure that the XML document does not contain malicious content (eg. XEE and XXE attacks).

Applying visitors

Deleting SAX Locator information from the class model:

public void optimize(PMML pmml){
  LocatorNullifier nullifier = new LocatorNullifier();
  nullifier.applyTo(pmml);
}

Marshalling

Storing live org.dmg.pmml.PMML instance into PMML schema version 4.4 document:

public void store(PMML pmml, OutputStream os) throws JAXBException {
  org.jpmml.model.PMMLUtil.marshal(pmml, os);
}

Example applications

Module pmml-model-example exemplifies the use of JPMML-Model library.

This module can be built using Apache Maven:

mvn clean install

The resulting uber-JAR file target/pmml-model-example-executable-1.6-SNAPSHOT.jar contains the following command-line applications:

  • org.jpmml.model.example.CopyExample (source). Copies and transforms a PMML schema version 3.X or 4.X document to a PMML schema version 4.4 document.
  • org.jpmml.model.example.ObfuscationExample (source). Obfuscates a PMML document by replacing field names with their MD5 hashes.
  • org.jpmml.model.example.TranslationExample (source). Translates a PMML document to a JSON or YAML document.
  • org.jpmml.model.example.ValidationExample (source). Validates a PMML document against the built-in XML Schema Definition (XSD) resource.

Copying input.pmml to output.pmml; the size of the class model is estimated using the Java agent technology:

java -javaagent:../pmml-agent/target/pmml-agent-1.6-SNAPSHOT.jar -cp target/pmml-model-example-executable-1.6-SNAPSHOT.jar org.jpmml.model.example.CopyExample --summary true --input input.pmml --output output.pmml

Translating a PMML XML document input.pmml to PMML JSON document output.json:

java -cp target/pmml-model-example-executable-1.6-SNAPSHOT.jar org.jpmml.model.example.TranslationExample --input input.pmml --output output.json --indent "\\t"

Checking the validity of model.pmml:

java -cp target/pmml-model-example-executable-1.6-SNAPSHOT.jar org.jpmml.model.example.ValidationExample --input model.pmml

Getting help:

java -cp target/pmml-model-example-executable-1.6-SNAPSHOT.jar <application class name> --help

It is possible to activate a specific Java XML Binding (JAXB) runtime by setting the value of the jakarta.xml.bind.JAXBContextFactory system property. Use org.glassfish.jaxb.runtime.v2.ContextFactory for activating a GlassFish Metro runtime, and org.eclipse.persistence.jaxb.JAXBContextFactory for activating an EclipseLink MOXy runtime.

For example:

java -Djakarta.xml.bind.JAXBContextFactoryy=org.eclipse.persistence.jaxb.JAXBContextFactory -cp target/pmml-model-example-executable-1.6-SNAPSHOT.jar ...

Documentation

Current:

Slightly outdated:

Support

Limited public support is available via the JPMML mailing list.

License

JPMML-Model is licensed under the BSD 3-Clause License.

Additional information

JPMML-Model 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-sparkml

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

jpmml-lightgbm

Java library and command-line application for converting LightGBM models to PMML
Java
160
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