{"library":"skl2onnx","title":"skl2onnx: Convert Scikit-learn Models to ONNX","description":"skl2onnx is a Python library that enables the conversion of scikit-learn machine learning models and pipelines into the ONNX (Open Neural Network Exchange) format. This conversion allows for improved model portability across different runtimes and often leads to enhanced inference performance, especially with ONNX Runtime. The library is actively maintained with frequent releases, typically on a monthly or bi-monthly cadence, and is currently at version 1.20.0.","language":"python","status":"active","last_verified":"Fri May 22","install":{"commands":["pip install skl2onnx onnx onnxruntime"],"cli":null},"imports":["from skl2onnx import to_onnx","from skl2onnx import convert_sklearn","from skl2onnx.common.data_types import FloatTensorType"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import numpy as np\nfrom sklearn.datasets import load_iris\nfrom sklearn.ensemble import RandomForestClassifier\nfrom skl2onnx import to_onnx\nimport onnxruntime as rt\n\n# 1. Train a scikit-learn model\niris = load_iris()\nX, y = iris.data, iris.target\nX = X.astype(np.float32) # ONNX typically uses float32\nmodel = RandomForestClassifier(n_estimators=10, random_state=42)\nmodel.fit(X, y)\n\n# 2. Convert the scikit-learn model to ONNX format\n# `X[:1]` is used to infer the input types and shapes\nonx_model = to_onnx(model, X[:1])\n\n# 3. Save the ONNX model to a file\nwith open(\"rf_iris.onnx\", \"wb\") as f:\n    f.write(onx_model.SerializeToString())\n\n# 4. Load and make predictions with ONNX Runtime\nsess = rt.InferenceSession(\"rf_iris.onnx\", providers=[\"CPUExecutionProvider\"])\ninput_name = sess.get_inputs()[0].name\noutput_names = [output.name for output in sess.get_outputs()]\n\n# Make a prediction\npredictions = sess.run(output_names, {input_name: X[0:1].astype(np.float32)})\n\nprint(f\"Original model prediction: {model.predict(X[0:1])}\")\nprint(f\"ONNX Runtime prediction (label): {predictions[0]}\")\nprint(f\"ONNX Runtime prediction (probabilities): {predictions[1]}\")","lang":"python","description":"This quickstart demonstrates how to train a simple RandomForestClassifier from scikit-learn, convert it to the ONNX format using `skl2onnx.to_onnx`, save the ONNX model to a file, and then load it with ONNX Runtime for inference. It highlights the typical workflow from training to ONNX-based prediction.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-22","installed_version":"1.20.0","pypi_latest":"1.20.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":50,"avg_install_s":15.5,"avg_import_s":4.21,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"skl2onnx","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"skl2onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":17.6,"import_time_s":2.81,"mem_mb":63,"disk_size":"491M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"skl2onnx","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"skl2onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":13.1,"import_time_s":4.84,"mem_mb":76,"disk_size":"453M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"skl2onnx","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"skl2onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":13.4,"import_time_s":5.59,"mem_mb":74.5,"disk_size":"437M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"skl2onnx","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"skl2onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":13.6,"import_time_s":4.81,"mem_mb":73.8,"disk_size":"435M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"skl2onnx","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"skl2onnx","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":19.9,"import_time_s":3.01,"mem_mb":60.1,"disk_size":"494M"}]}}