Java PMML API (legacy codebase)
Latest commit d63174f Mar 8, 2014 @vruusmann vruusmann Added a status notice

Java API for producing and scoring models in Predictive Model Markup Language (PMML).


This is a legacy codebase.

Starting from March 2014, this project has been superseded by JPMML-Model and JPMML-Evaluator projects.


Class model

  • Full support for PMML 3.0, 3.1, 3.2, 4.0 and 4.1 schemas:
    • Class hierarchy.
    • Schema version annotations.
  • Fluent API:
    • Value constructors.
  • SAX Locator information
  • Visitor pattern:
    • Validation agents.
    • Optimization and transformation agents.

Evaluation engine


JPMML library JAR files (together with accompanying Java source and Javadocs JAR files) are released via Maven Central Repository. Please join the JPMML mailing list for release announcements.

The current version is 1.0.22 (17 February, 2014).

Class model

<!-- Class model classes -->
<!-- Class model annotations -->

Evaluation engine



Class model

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.

There is not much documentation accompanying class model classes. The application developer should consult with the PMML specification about individual PMML elements and attributes.

Example applications

Evaluation engine

A model evaluator class can be instantiated directly when the contents of the PMML document is known:

PMML pmml = ...;

ModelEvaluator<TreeModel> modelEvaluator = new TreeModelEvaluator(pmml);

Otherwise, a PMML manager class should be instantiated first, which will inspect the contents of the PMML document and instantiate the right model evaluator class later:

PMML pmml = ...;

PMMLManager pmmlManager = new PMMLManager(pmml);

ModelEvaluator<?> modelEvaluator = (ModelEvaluator<?>)pmmlManager.getModelManager(null, ModelEvaluatorFactory.getInstance());

Model evaluator classes follow functional programming principles. Model evaluator instances are cheap enough to be created and discarded as needed (ie. not worth the pooling effort).

It is advisable for application code to work against the org.jpmml.evaluator.Evaluator interface:

Evaluator evaluator = (Evaluator)modelEvaluator;

An evaluator instance can be queried for the definition of active (ie. independent), predicted (ie. primary dependent) and output (ie. secondary dependent) fields:

List<FieldName> activeFields = evaluator.getActiveFields();
List<FieldName> predictedFields = evaluator.getPredictedFields();
List<FieldName> outputFields = evaluator.getOutputFields();

The PMML scoring operation must be invoked with valid arguments. Otherwise, the behaviour of the model evaluator class is unspecified.

The preparation of field values:

Map<FieldName, FieldValue> arguments = new LinkedHashMap<FieldName, FieldValue>();

List<FieldName> activeFields = evaluator.getActiveFields();
for(FieldName activeField : activeFields){
    // The raw (ie. user-supplied) value could be any Java primitive value
    Object rawValue = ...;

    // The raw value is passed through: 1) outlier treatment, 2) missing value treatment, 3) invalid value treatment and 4) type conversion
    FieldValue activeValue = evaluator.prepare(activeField, rawValue);

    arguments.put(activeField, activeValue);

The scoring:

Map<FieldName, ?> results = evaluator.evaluate(arguments);

Typically, a model has exactly one predicted field, which is called the target field:

FieldName targetName = evaluator.getTargetField();
Object targetValue = results.get(targetName);

The target value is either a Java primitive value (as a wrapper object) or an instance of org.jpmml.evaluator.Computable:

if(targetValue instanceof Computable){
    Computable computable = (Computable)targetValue;

    Object primitiveValue = computable.getResult();

The target value may implement interfaces that descend from interface org.jpmml.evaluator.ResultFeature:

// Test for "entityId" result feature
if(targetValue instanceof HasEntityId){
    HasEntityId hasEntityId = (HasEntityId)targetValue;
    HasEntityRegistry<?> hasEntityRegistry = (HasEntityRegistry<?>)evaluator;
    BiMap<String, ? extends Entity> entities = hasEntityRegistry.getEntityRegistry();
    Entity winner = entities.get(hasEntityId.getEntityId());

    // Test for "probability" result feature
    if(targetValue instanceof HasProbability){
        HasProbability hasProbability = (HasProbability)targetValue;
        Double winnerProbability = hasProbability.getProbability(winner.getId());
Example applications

Additional information

Please contact