Implementation:Microsoft Onnxruntime Sklearn Model Training
Appearance
Metadata
| Field | Value |
|---|---|
| Implementation Name | Sklearn_Model_Training |
| Repository | Microsoft_Onnxruntime |
| Source Repository | https://github.com/microsoft/onnxruntime |
| Type | External Tool Doc |
| External Tool | scikit-learn |
| Language | Python |
| Domain | ML_Inference, Model_Conversion |
| Last Updated | 2026-02-10 |
| Workflow | Train_Convert_Predict |
| Pair | 1 of 5 |
Overview
External tool documentation for training scikit-learn machine learning models as the first step in the ONNX conversion pipeline. The trained model will subsequently be converted to ONNX format for optimized inference.
API Signature
sklearn.linear_model.LogisticRegression().fit(X_train, y_train)
Or for ensemble models:
sklearn.ensemble.RandomForestClassifier(n_estimators=10).fit(X_train, y_train)
Import
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
Code Reference
| Reference | Location |
|---|---|
| LogisticRegression training | docs/python/examples/plot_train_convert_predict.py:L22-34 |
| RandomForest training | docs/python/examples/plot_train_convert_predict.py:L178-181 |
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
X_train |
numpy.ndarray |
Yes | Training feature matrix with shape (n_samples, n_features).
|
y_train |
numpy.ndarray |
Yes | Training label vector with shape (n_samples,).
|
Outputs
| Output | Type | Description |
|---|---|---|
| Trained model | scikit-learn estimator object | A fitted model object containing learned parameters, ready for conversion to ONNX format. |
Usage Example
LogisticRegression Training
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y)
clr = LogisticRegression()
clr.fit(X_train, y_train)
From the source at docs/python/examples/plot_train_convert_predict.py:L22-34:
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y)
clr = LogisticRegression()
clr.fit(X_train, y_train)
RandomForestClassifier Training
From the source at docs/python/examples/plot_train_convert_predict.py:L178-181:
from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(n_estimators=10)
rf.fit(X_train, y_train)
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment