From scikit-learn to ONNX#

Function skl2onnx.to_onnx is the main entrypoint to convert a scikit-learn pipeline into ONNX. The same function was extended in this package into to_onnx to handle dataframes, an extended list of supported converters, scorers. It works exactly the same:

<<<

import numpy
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.cluster import KMeans
from mlprodict.onnx_conv import to_onnx
from mlprodict.onnxrt import OnnxInference

iris = load_iris()
X = iris.data.astype(numpy.float32)
X_train, X_test = train_test_split(X)
clr = KMeans(n_clusters=3)
clr.fit(X_train)

model_def = to_onnx(clr, X_train.astype(numpy.float32),
                    target_opset=12)

oinf = OnnxInference(model_def, runtime='python')
print(oinf.run({'X': X_test[:5]}))

>>>

    {'label': array([0, 2, 0, 1, 1]), 'scores': array([[0.926, 4.119, 1.014],
           [1.891, 4.99 , 0.399],
           [0.807, 3.81 , 1.327],
           [3.508, 0.983, 5.008],
           [3.334, 0.191, 5.021]], dtype=float32)}

This new version extends the conversion to scorers through convert_scorer.