skl2onnx


Nameskl2onnx JSON
Version 1.18.0 PyPI version JSON
download
home_pagehttps://github.com/onnx/sklearn-onnx
SummaryConvert scikit-learn models to ONNX
upload_time2024-12-18 07:25:09
maintainerNone
docs_urlNone
authorONNX
requires_pythonNone
licenseApache License v2.0
keywords
VCS
bugtrack_url
requirements onnx scikit-learn onnxconverter-common
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Introduction
*sklearn-onnx* converts [scikit-learn](https://scikit-learn.org/stable/) models to [ONNX](https://github.com/onnx/onnx).
Once in the ONNX format, you can use tools like [ONNX Runtime](https://github.com/Microsoft/onnxruntime) for high performance scoring.
All converters are tested with [onnxruntime](https://onnxruntime.ai/).
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/](https://onnx.ai/sklearn-onnx/).
[Supported scikit-learn Models](https://onnx.ai/sklearn-onnx/supported.html)
Last supported opset is 21.

You may also find answers in [existing issues](https://github.com/onnx/sklearn-onnx/issues?utf8=%E2%9C%93&q=is%3Aissue)
or submit a new one.

## Installation
You can install from [PyPi](https://pypi.org/project/skl2onnx/):
```
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

```python
# 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
[Apache License v2.0](LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/onnx/sklearn-onnx",
    "name": "skl2onnx",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "ONNX",
    "author_email": "onnx-technical-discuss@lists.lfaidata.foundation",
    "download_url": "https://files.pythonhosted.org/packages/a9/fb/f91b284365bab4ddcb0f77f573e60dc96bc232648de997814e3ddd832e97/skl2onnx-1.18.0.tar.gz",
    "platform": null,
    "description": "## Introduction\r\n*sklearn-onnx* converts [scikit-learn](https://scikit-learn.org/stable/) models to [ONNX](https://github.com/onnx/onnx).\r\nOnce in the ONNX format, you can use tools like [ONNX Runtime](https://github.com/Microsoft/onnxruntime) for high performance scoring.\r\nAll converters are tested with [onnxruntime](https://onnxruntime.ai/).\r\nAny external converter can be registered to convert scikit-learn pipeline\r\nincluding models or transformers coming from external libraries.\r\n\r\n## Documentation\r\nFull documentation including tutorials is available at [https://onnx.ai/sklearn-onnx/](https://onnx.ai/sklearn-onnx/).\r\n[Supported scikit-learn Models](https://onnx.ai/sklearn-onnx/supported.html)\r\nLast supported opset is 21.\r\n\r\nYou may also find answers in [existing issues](https://github.com/onnx/sklearn-onnx/issues?utf8=%E2%9C%93&q=is%3Aissue)\r\nor submit a new one.\r\n\r\n## Installation\r\nYou can install from [PyPi](https://pypi.org/project/skl2onnx/):\r\n```\r\npip install skl2onnx\r\n```\r\nOr you can install from the source with the latest changes.\r\n```\r\npip install git+https://github.com/onnx/sklearn-onnx.git\r\n```\r\n\r\n## Getting started\r\n\r\n```python\r\n# Train a model.\r\nimport numpy as np\r\nfrom sklearn.datasets import load_iris\r\nfrom sklearn.model_selection import train_test_split\r\nfrom sklearn.ensemble import RandomForestClassifier\r\n\r\niris = load_iris()\r\nX, y = iris.data, iris.target\r\nX = X.astype(np.float32)\r\nX_train, X_test, y_train, y_test = train_test_split(X, y)\r\nclr = RandomForestClassifier()\r\nclr.fit(X_train, y_train)\r\n\r\n# Convert into ONNX format.\r\nfrom skl2onnx import to_onnx\r\n\r\nonx = to_onnx(clr, X[:1])\r\nwith open(\"rf_iris.onnx\", \"wb\") as f:\r\n    f.write(onx.SerializeToString())\r\n\r\n# Compute the prediction with onnxruntime.\r\nimport onnxruntime as rt\r\n\r\nsess = rt.InferenceSession(\"rf_iris.onnx\", providers=[\"CPUExecutionProvider\"])\r\ninput_name = sess.get_inputs()[0].name\r\nlabel_name = sess.get_outputs()[0].name\r\npred_onx = sess.run([label_name], {input_name: X_test.astype(np.float32)})[0]\r\n```\r\n\r\n## Contribute\r\nWe welcome contributions in the form of feedback, ideas, or code.\r\n\r\n## License\r\n[Apache License v2.0](LICENSE)\r\n",
    "bugtrack_url": null,
    "license": "Apache License v2.0",
    "summary": "Convert scikit-learn models to ONNX",
    "version": "1.18.0",
    "project_urls": {
        "Homepage": "https://github.com/onnx/sklearn-onnx"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "08dee8825727acd80484aa28080de62e4dc21f076d6887c10db49e2c8a66578f",
                "md5": "ee7745d4a4a8427da97359f72bf1fd6d",
                "sha256": "1345d8a1d3aa4a11abfbed4bc984b777023dad85e1c9fe4eb727cba5ee0fcaa8"
            },
            "downloads": -1,
            "filename": "skl2onnx-1.18.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ee7745d4a4a8427da97359f72bf1fd6d",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 300310,
            "upload_time": "2024-12-18T07:25:06",
            "upload_time_iso_8601": "2024-12-18T07:25:06.469213Z",
            "url": "https://files.pythonhosted.org/packages/08/de/e8825727acd80484aa28080de62e4dc21f076d6887c10db49e2c8a66578f/skl2onnx-1.18.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a9fbf91b284365bab4ddcb0f77f573e60dc96bc232648de997814e3ddd832e97",
                "md5": "83c5915b090ec3f6956472cd21c0eec1",
                "sha256": "39ea4ae30c5c182355a1824467013158214444e0ce0b18f33338bd827d4fb00f"
            },
            "downloads": -1,
            "filename": "skl2onnx-1.18.0.tar.gz",
            "has_sig": false,
            "md5_digest": "83c5915b090ec3f6956472cd21c0eec1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 935240,
            "upload_time": "2024-12-18T07:25:09",
            "upload_time_iso_8601": "2024-12-18T07:25:09.448106Z",
            "url": "https://files.pythonhosted.org/packages/a9/fb/f91b284365bab4ddcb0f77f573e60dc96bc232648de997814e3ddd832e97/skl2onnx-1.18.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 07:25:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "onnx",
    "github_project": "sklearn-onnx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "onnx",
            "specs": [
                [
                    ">=",
                    "1.2.1"
                ]
            ]
        },
        {
            "name": "scikit-learn",
            "specs": [
                [
                    ">=",
                    "1.1"
                ]
            ]
        },
        {
            "name": "onnxconverter-common",
            "specs": [
                [
                    ">=",
                    "1.7.0"
                ]
            ]
        }
    ],
    "lcname": "skl2onnx"
}
        
Elapsed time: 0.45770s