Registry / ai-ml / sklearn2pmml

sklearn2pmml

JSON →
library0.133.0pypypi✓ verified 21d ago

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.

pip install sklearn2pmml
INSTALL
IMPORT
SIG · SKLEARN2PMML
S
sklearn2pmml
ai-mlpythonv0.133.0
Install
14.3s avg
Import
4504ms
Disk
363MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.133.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
build_error
glibc
py 3.103.95 runs
installs and imports cleanly · install 14.3s · import 4.504s · 351MB
363MB installed
● package 363MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PMMLPipeline
from sklearn2pmml.pipeline import PMMLPipeline
sklearn2pmml
from sklearn2pmml import sklearn2pmml
from sklearn2pmml import make_pmml_pipeline
The `make_pmml_pipeline` utility function has been removed or deprecated in favor of directly using `PMMLPipeline` and `sklearn2pmml()`.

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}")
Debug
Known issues
breakingThe `sklearn2pmml.make_pmml_pipeline()` utility function has been removed. Additionally, the `escape_func` parameter was moved from `make_pmml_pipeline()` to the `sklearn2pmml()` function.
fix
Directly use `sklearn2pmml.pipeline.PMMLPipeline` for pipeline creation and pass `escape_func` (if needed) to `sklearn2pmml()`.
affects: 0.120.0 and newer
gotchasklearn2pmml is a Python wrapper for a Java library and requires a Java Runtime Environment (JRE) version 11 or newer to be installed and accessible via the system's PATH environment variable. Without Java, conversion attempts will fail with a `RuntimeError`.
fix
Ensure Java 11+ is installed and configured correctly on your system path.
affects: All versions
gotchaThe `sklearn2pmml` library is designed for *exporting* Scikit-learn models to PMML. It does not provide functionality to *import* PMML files back into Scikit-learn objects or Python for native scoring. For Python-based PMML evaluation, consider using the `jpmml-evaluator-python` library.
fix
Use `jpmml-evaluator-python` or another PMML evaluation library if you need to score PMML files within Python.
affects: All versions
gotchaWhen training models within `PMMLPipeline`, using `pandas.DataFrame` or `pandas.Series` for `X` and `y` is recommended. This allows `sklearn2pmml` to correctly capture and embed meaningful feature and target names in the PMML file. If NumPy arrays are used, feature names will default to generic 'x1', 'x2', etc., and the target name to 'y'.
fix
Pass `X` and `y` as `pandas.DataFrame` and `pandas.Series` objects, respectively, to the `fit()` method of `PMMLPipeline`.
affects: All versions
gotchaDirect conversion of highly custom Python classes, especially for complex data preprocessing (e.g., advanced text feature extraction using third-party libraries), is generally not supported. PMML has a limited set of expressible transformations, and arbitrary Python code cannot be translated.
fix
Refactor complex custom preprocessing steps into simpler, PMML-compatible transformers where possible, or perform them external to the PMML pipeline.
affects: All versions
gotchaConversion of large or complex models can lead to out-of-memory errors in the underlying Java process. This often manifests as a `RuntimeError` with Java-related stack traces.
fix
Increase the Java Virtual Machine (JVM) memory allocation by passing `java_opts` to the `sklearn2pmml()` function, e.g., `sklearn2pmml(pipeline, 'model.pmml', java_opts=['-Xms4096m', '-Xmx4096m'])` to allocate 4GB of heap space.
affects: All versions
Errors
Common errors & fixes
OSError: [Errno 2] No such file or directory: 'java'
The 'java' executable is not found in the system's PATH, or JAVA_HOME is not correctly set, which prevents sklearn2pmml from invoking the underlying JPMML-SkLearn Java library.
fix
Install a Java Development Kit (JDK) and ensure the 'java' executable is accessible via your system's PATH, or set the JAVA_HOME environment variable to the JDK installation directory.
ModuleNotFoundError: No module named 'sklearn2pmml'
The 'sklearn2pmml' library has not been installed in the current Python environment or the environment is not active.
fix
Install the library using pip: `pip install sklearn2pmml`
sklearn2pmml.converter.ConversionError: Type '...' is not a JPMML-SkLearn supported ...
The Scikit-Learn estimator, transformer, or specific configuration used in the pipeline is not yet supported by the underlying JPMML-SkLearn Java library.
fix
Refer to the `jpmml-sklearn` documentation for a list of supported Scikit-Learn components and consider replacing unsupported parts of your pipeline with supported alternatives, or use a custom transformer that can be converted.
AttributeError: 'ColumnTransformer' object has no attribute 'transformers_'
This error typically indicates a version incompatibility between `sklearn2pmml` and the installed `scikit-learn` library, or that the `ColumnTransformer` (or pipeline) has not been fitted before conversion.
fix
Ensure your Scikit-Learn version is compatible with `sklearn2pmml` (check documentation for requirements), and always `fit()` your pipeline or estimator before attempting to convert it to PMML. If the issue persists, downgrade or upgrade `scikit-learn` to a compatible version.
Upgrade
Version history
0.133.0latest on PyPI · released Aug 19, 2026
Audit
Dependencies
Java 11 or newerrequiredsklearn2pmml is a wrapper around a Java library (JPMML-SkLearn) and requires a compatible Java Runtime Environment (JRE) to be installed and available on the system path.
scikit-learnrequiredCore functionality involves converting Scikit-Learn models and pipelines.
jpmml-evaluatoroptionalUsed for evaluating (scoring) PMML models in Python, often in conjunction with models generated by sklearn2pmml.
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
sklearn2pmml — pip install sklearn2pmml · libregistry