The SuperML PMML (Predictive Model Markup Language) module provides comprehensive functionality to export trained SuperML models to the standard PMML format. This enables model deployment and interoperability across different ML platforms and systems.
- LinearRegression - Ordinary Least Squares regression
- LogisticRegression - Binary and multiclass classification
- Ridge - L2 regularized linear regression
- Lasso - L1 regularized linear regression
- DecisionTree - Classification and regression trees
- RandomForest - Ensemble of decision trees
- Full PMML 4.4 compliance with proper schema validation
- Comprehensive metadata including headers, timestamps, and model provenance
- Feature name mapping with custom field names and data types
- Model parameter extraction including coefficients, tree structures, and ensemble configurations
- Validation functionality to ensure PMML correctness
- Cross-platform compatibility for deployment to PMML consumers
import org.superml.pmml.PMMLConverter;
import org.superml.linear_model.LinearRegression;
// Train a model
LinearRegression model = new LinearRegression();
model.fit(X, y);
// Convert to PMML
PMMLConverter converter = new PMMLConverter();
String pmmlXml = converter.convertToXML(model);
// Validate the PMML
boolean isValid = converter.validatePMML(pmmlXml);
System.out.println("PMML is valid: " + isValid);// Custom feature names and target
String[] featureNames = {"age", "income", "education"};
String targetName = "salary";
String pmmlXml = converter.convertToXML(model, featureNames, targetName);
// Save to file for deployment
Files.write(Paths.get("model.pmml"), pmmlXml.getBytes());String convertToXML(Object model)
- Converts a SuperML model to PMML XML format with default feature names
- Parameters:
model- Trained SuperML model (must extend BaseEstimator) - Returns: PMML XML string
- Throws:
IllegalArgumentExceptionfor unsupported models
String convertToXML(Object model, String[] featureNames, String targetName)
- Converts a SuperML model to PMML XML with custom field names
- Parameters:
model- Trained SuperML modelfeatureNames- Array of feature names (null for default)targetName- Target variable name
- Returns: PMML XML string
boolean validatePMML(String pmmlXml)
- Validates PMML XML against schema requirements
- Parameters:
pmmlXml- PMML XML string to validate - Returns:
trueif valid,falseotherwise
Object convertFromXML(String pmmlXml)
- Converts PMML XML back to SuperML model (Not yet implemented)
- Throws:
UnsupportedOperationException
<RegressionModel functionName="regression">
<RegressionTable intercept="1.23">
<NumericPredictor name="feature_0" coefficient="2.45"/>
<NumericPredictor name="feature_1" coefficient="-0.67"/>
</RegressionTable>
</RegressionModel>Key Features:
- Extracts coefficients via
model.getCoefficients() - Includes intercept via
model.getIntercept() - Lasso automatically excludes zero coefficients
- Ridge includes regularization metadata
<RegressionModel functionName="classification" normalizationMethod="logit">
<RegressionTable intercept="0.5" targetCategory="1">
<NumericPredictor name="age" coefficient="0.123"/>
<NumericPredictor name="income" coefficient="-0.045"/>
</RegressionTable>
</RegressionModel>Key Features:
- Supports binary and multiclass classification
- Includes class labels from
model.getClasses() - Uses logit normalization for proper probability interpretation
<TreeModel functionName="regression">
<Node>
<Node>
<SimplePredicate field="age" operator="lessOrEqual" value="35.0"/>
<Node score="45000"/>
</Node>
<Node>
<SimplePredicate field="age" operator="greaterThan" value="35.0"/>
<Node score="65000"/>
</Node>
</Node>
</TreeModel>Key Features:
- Recursive tree structure conversion from
model.getTree() - Split conditions with feature indices and thresholds
- Leaf nodes with prediction values
- Supports both classification and regression
<MiningModel functionName="classification" multipleModelMethod="majorityVote">
<Segmentation multipleModelMethod="majorityVote">
<Segment id="tree_0">
<TreeModel functionName="classification">
<!-- Individual tree structure -->
</TreeModel>
</Segment>
<!-- Additional tree segments -->
</Segmentation>
</MiningModel>Key Features:
- Ensemble representation using MiningModel
- Individual trees as segments
- Majority vote for classification, averaging for regression
- Bootstrap sampling metadata (when available)
-
Header Section
<Header> <Application name="SuperML Java Framework" version="3.1.2"/> <Timestamp>2024-01-15 10:30:00</Timestamp> </Header>
-
Data Dictionary
<DataDictionary> <DataField name="feature_0" optype="continuous" dataType="double"/> <DataField name="target" optype="continuous" dataType="double"/> </DataDictionary>
-
Mining Schema
<MiningSchema> <MiningField name="feature_0" usageType="active"/> <MiningField name="target" usageType="target"/> </MiningSchema>
-
Model-Specific Elements (varies by algorithm)
The PMML module uses the following dependencies (defined in pom.xml):
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-model</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.jpmml</groupId>
<artifactId>pmml-evaluator</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>3.0.2</version>
<scope>runtime</scope>
</dependency>For comprehensive usage examples, see the SuperML Examples module:
- File:
superml-examples/src/main/java/org/superml/examples/PMMLConversionExample.java - Features: Business and technical model examples, deployment scenarios, validation demonstrations
For testing and validation demos, see the SuperML Test Cases module:
- Files:
superml-testcases/src/test/java/org/superml/pmml/PMMLConverterDemo.java- Basic functionality demonstrationPMMLIntegrationTest.java- Integration testing with mock models
# From the superml-pmml directory
mvn clean compile
# Or build all modules including dependencies
mvn clean compile -pl superml-core,superml-linear-models,superml-tree-models,superml-pmml# From the superml-testcases directory
cd ../superml-testcases
mvn compile test-compile
# Run the PMML converter demo
java -cp "target/test-classes:../superml-pmml/target/classes:../superml-pmml/target/dependency/*" \
org.superml.pmml.PMMLConverterDemo# From the superml-examples directory
cd ../superml-examples
mvn compile
# Run the PMML conversion example
java -cp "target/classes:../superml-pmml/target/classes:../superml-pmml/target/dependency/*" \
org.superml.examples.PMMLConversionExample=== SuperML PMML Converter Demo ===
1. Testing PMML Validation
===========================
✓ null input: INVALID
✓ empty string: INVALID
✓ whitespace only: INVALID
✓ malformed XML: INVALID
✓ valid XML but not PMML: INVALID
✓ sample PMML structure: VALID
2. Testing Error Handling
==========================
✓ Null model: Correctly threw IllegalArgumentException
✓ Unsupported model: Correctly threw IllegalArgumentException
✓ convertFromXML: Correctly threw UnsupportedOperationException
3. Testing Method Availability
===============================
✓ convertToXML(Object) method available
✓ convertToXML(Object, String[], String) method available
✓ convertFromXML(String) method available
✓ validatePMML(String) method available
✓ All required methods are available
=== Demo Complete ===
======================================================================
SuperML PMML Conversion Examples
======================================================================
🔄 1. Basic PMML Conversion
========================================
📈 Linear Regression to PMML:
✓ PMML generated: 2,450 characters
✓ Validation result: VALID
✓ Model type: Linear Regression
🎯 Logistic Regression to PMML:
✓ PMML generated: 2,650 characters
✓ Validation result: VALID
✓ Model type: Logistic Regression
⚡ 2. Advanced PMML with Custom Features
========================================
💼 Business Model with Custom Features:
✓ Features: customer_age, annual_income, credit_score, debt_to_income_ratio
✓ Target: loan_approval_probability
✓ PMML size: 2,850 characters
✓ Validation: PASSED
🚀 4. Production Deployment Scenarios
========================================
⚡ Spark MLlib Deployment:
✓ Model: Random Forest
✓ Features: 4
✓ Ready for Spark deployment: YES
📋 Usage: Load in Spark MLlib using JPMML-SparkML
======================================================================
✅ All PMML conversion examples completed successfully!
======================================================================
import org.apache.spark.ml.Pipeline
import org.jpmml.sparkml.PMMLBuilder
// Load PMML in Spark
val pmmlModel = PMMLBuilder.load("model.pmml")from sklearn2pmml import sklearn2pmml
from jpmml_evaluator import make_evaluator
# Load SuperML PMML in Python
evaluator = make_evaluator("model.pmml")
predictions = evaluator.evaluate(data)library(pmml)
# Load and evaluate PMML
model <- pmml::loadPMML("model.pmml")
predictions <- predict(model, newdata)- SAS Enterprise Miner - Direct PMML import
- IBM SPSS - PMML model scoring
- Amazon SageMaker - PMML container deployment
- Microsoft Azure ML - PMML endpoint hosting
- convertFromXML not yet implemented (PMML → SuperML)
- RandomForest uses placeholder structure (individual trees not accessible)
- LogisticRegression coefficients not directly exposed (uses approximation)
- Neural networks not yet supported (interfaces exist but limited implementation)
- Full bidirectional PMML conversion (import from PMML)
- Support for preprocessing transformations (StandardScaler, etc.)
- Enhanced Random Forest with actual tree extraction
- Neural network PMML support (MLPClassifier, CNNClassifier)
- Custom PMML extensions for SuperML-specific features
- Performance optimization for large models
// Train a complete ML pipeline
Pipeline pipeline = new Pipeline()
.addStep("scaler", new StandardScaler())
.addStep("classifier", new LogisticRegression());
pipeline.fit(X, y);
// Export individual components to PMML
// (Full pipeline PMML support planned for future versions)
LogisticRegression model = (LogisticRegression) pipeline.getStep("classifier");
String pmml = converter.convertToXML(model, featureNames, "outcome");// Train multiple models for comparison
LinearRegression baseModel = new LinearRegression();
Ridge ridgeModel = new Ridge().setAlpha(0.1);
baseModel.fit(X, y);
ridgeModel.fit(X, y);
// Export both models to PMML for parallel deployment
String basePMML = converter.convertToXML(baseModel, features, "prediction");
String ridgePMML = converter.convertToXML(ridgeModel, features, "prediction");
// Deploy both models for A/B testing
savePMMLToFile(basePMML, "base_model.pmml");
savePMMLToFile(ridgePMML, "ridge_model.pmml");// Train in SuperML Java
DecisionTree javaModel = new DecisionTree().setMaxDepth(5);
javaModel.fit(trainingData, labels);
// Export to PMML
String pmml = converter.convertToXML(javaModel);
// Deploy to various platforms:
// - Python: Use jpmml-evaluator
// - R: Use pmml package
// - Spark: Use pmml-sparkml
// - Cloud: Deploy to MLaaS platformsContributions to the PMML module are welcome! Areas of particular interest:
- PMML Import - Implementing
convertFromXMLfunctionality - Model Support - Adding support for additional SuperML algorithms
- Preprocessing - PMML export for data transformation steps
- Optimization - Performance improvements for large models
- Testing - Comprehensive test coverage and validation
Please follow the SuperML contribution guidelines and ensure all changes maintain PMML 4.4 compliance.
This module is licensed under the Apache License 2.0, consistent with the broader SuperML Java framework.