<jupyter_start><jupyter_text>Link: http://onnx.ai/sklearn-onnx/index.html<jupyter_code># Train a model.
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.neighbors import KNeighborsClassifier

iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y)
# clr = RandomForestClassifier()
clr = KNeighborsClassifier()

clr.fit(X_train, y_train)
# Convert into ONNX format
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType

initial_type = [('float_input', FloatTensorType([None, 4]))]
onx = convert_sklearn(clr, initial_types=initial_type)

# filename = '../models/rf_iris.onnx'
filename = '../models/knn_iris.onnx'
with open(filename, "wb") as f:
    f.write(onx.SerializeToString())
# Compute the prediction with ONNX Runtime
import onnxruntime as rt
import numpy

sess = rt.InferenceSession(filename)

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(numpy.float32)})[0]
pred_onx
clr.predict(X_test)<jupyter_output><empty_output><jupyter_text>Converting ONNX models to ORT formatLink: https://onnxruntime.ai/docs/tutorials/mobile/model-conversion.html<jupyter_code># ! python -m onnxruntime.tools.convert_onnx_models_to_ort "../models/rf_iris.onnx"
! python -m onnxruntime.tools.convert_onnx_models_to_ort "../models/knn_iris.onnx"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11692506459948321, 'fraction_numerical': 0.00516795865633075, 'mean_word_length': 6.78391959798995, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '590132', 'license': 'MIT', 'n_tokens_mistral': 586, 'n_tokens_neox': 572, 'n_words': 106, 'path': 'notebooks/skl2onnx00_quisckstart.ipynb', 'repo_name': 'dwelcaslu/onnx-android-ml-pipeline', 'size': '1548'}