Quick search


version 0.0.2

Simple exporter of sklearn models into PMML.

People: V\xe1clav \u010cadek



sklearn2pmml is simple exporter for sklearn models (for supported models see bellow) into PMML text format which address
the problems mentioned bellow.

Storing predictive models using binary format (e.g. Pickle) may be dangerous from several perspectives - naming few:

* **binary compatibility**:you update the libraries and may not be able to open the model serialized with older version
* **dangerous code**: when you would use model made by someone else
* **interpretability**: model cannot be easily opened and reviewed by human
* etc.

In addition the PMML is able to persist scaling of the raw input features which helps gradient descent to run smoothly
through optimization space.


To install sklearn2pmml, simply:

.. code-block:: bash

$ pip install sklearn2pmml


Example on Iris data - for more examples see the examples folder.

.. code-block:: python

from scikit2pmml import scikit2pmml
from sklearn.datasets import load_iris
import numpy as np
from sklearn.ensemble import RandomForestClassifier

iris = load_iris()
X =
y =

model = RandomForestClassifier(max_depth=2, n_estimators=10, random_state=0), y)

params = {
'pmml_version': '4.2',
'feature_names': iris.feature_names,
'target_values': iris.target_names,
'target_name': 'specie',
'copyright': 'V\xe1clav \u010cadek',
'description': 'Simple Iris RF model.',
'model_name': 'Iris Model'

scikit2pmml(estimator=model, file='iris.pmml', **params)

Params explained
- **estimator**: Sklearn model to be exported as PMML (for supported models - see bellow).
- **transformer**: if provided (and it's supported - see bellow) then scaling is applied to data fields.
- **file**: name of the file where the PMML will be exported.
- **feature_names**: when provided and have same shape as input layer, then features will have custom names, otherwise generic names (x\\ :sub:`0`\\,..., x\\ :sub:`n-1`\\) will be used.
- **target_values**: when provided and have same shape as output layer, then target values will have custom names, otherwise generic names (y\\ :sub:`0`\\,..., y\\ :sub:`n-1`\\) will be used.
- **target_name**: when provided then target variable will have custom name, otherwise generic name **class** will be used.
- **copyright**: who is the author of the model.
- **description**: optional parameter that sets *description* within PMML document.
- **model_name**: optional parameter that sets *model_name* within PMML document.

What is supported?
- Linear Model
* sklearn.linear_model.LinearRegression
* sklearn.linear_model.LogisticRegression
- Tree
* sklearn.tree.DecisionTree
* sklearn.tree.ExtraTreeClassifier
- Ensemble
* sklearn.ensemble.RandomForestClassifier
* sklearn.ensemble.ExtraTreesClassifier
- Scalers
* sklearn.preprocessing.StandardScaler
* sklearn.preprocessing.MinMaxScaler


This software is licensed under MIT licence.




You can download the latest distribution from PyPI here:

Using pip

You can install scikit2pmml for yourself from the terminal by running:

pip install --user scikit2pmml

If you want to install it for all users on your machine, do:

pip install scikit2pmml
On Linux, do sudo pip install scikit2pmml.

If you don't yet have the pip tool, you can get it following these instructions.

This package was discovered in PyPI.