Convert scikit-learn models to ONNX
Project Links
Meta
Author: ONNX Contributors
Requires Python: >=3.8
Classifiers
Development Status
- 4 - Beta
Environment
- Console
Intended Audience
- Developers
Operating System
- MacOS :: MacOS X
- Microsoft :: Windows
Programming Language
- Python
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
License
- OSI Approved :: Apache Software License

Introduction
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.
Documentation
Full documentation including tutorials is available at https://onnx.ai/sklearn-onnx/. Supported scikit-learn Models Last supported opset is 21.
You may also find answers in existing issues or submit a new one.
Installation
You can install from PyPi:
pip install skl2onnx
Or you can install from the source with the latest changes.
pip install git+https://github.com/onnx/sklearn-onnx.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 = iris.data, iris.target
X = X.astype(np.float32)
X_train, X_test, y_train, y_test = train_test_split(X, y)
clr = RandomForestClassifier()
clr.fit(X_train, 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:
f.write(onx.SerializeToString())
# 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 = sess.run([label_name], {input_name: X_test.astype(np.float32)})[0]
Contribute
We welcome contributions in the form of feedback, ideas, or code.
License
1.19.1
May 28, 2025
1.19.0
May 28, 2025
1.18.0
Dec 18, 2024
1.17.0
May 30, 2024
1.16.0
Dec 12, 2023
1.15.0
Aug 07, 2023
1.14.1
May 09, 2023
1.14.0
Mar 02, 2023
1.13
Sep 26, 2022
1.12
Aug 04, 2022
1.11.2
May 24, 2022
1.11.1
Mar 31, 2022
1.11
Feb 28, 2022
1.10.4
Jan 19, 2022
1.10.3
Nov 26, 2021
1.10.2
Nov 19, 2021
1.10.0
Oct 02, 2021
1.9.3
Sep 21, 2021
1.9.2
Aug 17, 2021
1.9.1
Aug 11, 2021
1.9.0
Jul 02, 2021
1.8.0
Mar 02, 2021
1.7.0
Jun 08, 2020
1.6.1
Apr 04, 2020
1.6.0
Nov 08, 2019
1.5.2
Oct 03, 2019
1.5.1
Aug 29, 2019
1.5.0
Jun 11, 2019
1.4.9
May 16, 2019
1.4.8
May 08, 2019
1.4.7
Apr 25, 2019
1.4.6
Apr 18, 2019
1.4.5
Mar 20, 2019
1.4.4.2
Mar 16, 2019
1.4.4.1
Mar 16, 2019
1.4.4
Mar 15, 2019
1.4.3
Feb 26, 2019
1.4.2
Jan 26, 2019
1.4.0
Jan 24, 2019