Skip to main content

Convert scikit-learn models to ONNX

Project description


sklearn-onnx converts scikit-learn models to ONNX. Once in the ONNX format, you can use tools like ONNX Runtime for high performance scoring. All converters are tested with onnxruntime. Any external converter can be registered to convert scikit-learn pipeline including models or transformers coming from external libraries.


Full documentation including tutorials is available at Supported scikit-learn Models Last supported opset is 21.

You may also find answers in existing issues or submit a new one.


You can install from PyPi:

pip install skl2onnx

Or you can install from the source with the latest changes.

pip install git+

Getting started

# Train a model.
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier

iris = load_iris()
X, y =,
X = X.astype(np.float32)
X_train, X_test, y_train, y_test = train_test_split(X, y)
clr = RandomForestClassifier(), y_train)

# Convert into ONNX format.
from skl2onnx import to_onnx

onx = to_onnx(clr, X[:1])
with open("rf_iris.onnx", "wb") as f:

# Compute the prediction with onnxruntime.
import onnxruntime as rt

sess = rt.InferenceSession("rf_iris.onnx", providers=["CPUExecutionProvider"])
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
pred_onx =[label_name], {input_name: X_test.astype(np.float32)})[0]


We welcome contributions in the form of feedback, ideas, or code.


Apache License v2.0

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skl2onnx-1.17.0.tar.gz (932.0 kB view hashes)

Uploaded Source

Built Distribution

skl2onnx-1.17.0-py2.py3-none-any.whl (298.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page