Scikit-Learn to PMML Converter

0.130.0 · active · verified Mon Apr 13

sklearn2pmml is a Python library designed for converting Scikit-Learn pipelines and estimators into the Predictive Model Markup Language (PMML) format. It acts as a thin Python wrapper around the JPMML-SkLearn Java library, enabling the export of trained machine learning models for deployment in environments that support PMML. The current version is 0.130.0, released on April 4, 2026, and the library is actively maintained.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a Scikit-Learn pipeline, wrap it with `PMMLPipeline`, fit the model, and then export it to a PMML file using the `sklearn2pmml()` function. The `PMMLPipeline` class enhances the standard Scikit-Learn pipeline with PMML-specific functionalities like capturing feature names from Pandas DataFrames.

import pandas as pd
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
from sklearn2pmml.pipeline import PMMLPipeline
from sklearn2pmml import sklearn2pmml

# Load a sample dataset
iris = load_iris(as_frame=True)
X, y = iris.data, iris.target

# Create a PMMLPipeline (extends sklearn.pipeline.Pipeline)
pmml_pipeline = PMMLPipeline([
    ('classifier', DecisionTreeClassifier())
])

# Fit the pipeline
pmml_pipeline.fit(X, y)

# Convert the fitted pipeline to PMML
pmml_filepath = 'DecisionTreeIris.pmml'
sklearn2pmml(pmml_pipeline, pmml_filepath)

print(f"PMML model successfully exported to {pmml_filepath}")

view raw JSON →