skl2onnx


Nameskl2onnx JSON
Version 1.16.0 PyPI version JSON
download
home_pagehttps://github.com/onnx/sklearn-onnx
SummaryConvert scikit-learn models to ONNX
upload_time2023-12-12 05:49:38
maintainer
docs_urlNone
authorONNX
requires_python
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 15.

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": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "ONNX",
    "author_email": "onnx-technical-discuss@lists.lfaidata.foundation",
    "download_url": "https://files.pythonhosted.org/packages/e9/3f/f624c1d30324597c419006a826ad095345c7457f75a2e23a65cfb2118cb1/skl2onnx-1.16.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 15.\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.16.0",
    "project_urls": {
        "Homepage": "https://github.com/onnx/sklearn-onnx"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2680836824c62ff0923b4c3b8af8332170bdc3ccb469a220535b40405a93b4fb",
                "md5": "62d2a9c1aab364d11d925bd25cd61cb7",
                "sha256": "7de548580c625bfa5893fe79c9dd3213c3720b12e1ff8e3fd28967da0698242d"
            },
            "downloads": -1,
            "filename": "skl2onnx-1.16.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "62d2a9c1aab364d11d925bd25cd61cb7",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 298473,
            "upload_time": "2023-12-12T05:49:35",
            "upload_time_iso_8601": "2023-12-12T05:49:35.507734Z",
            "url": "https://files.pythonhosted.org/packages/26/80/836824c62ff0923b4c3b8af8332170bdc3ccb469a220535b40405a93b4fb/skl2onnx-1.16.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e93ff624c1d30324597c419006a826ad095345c7457f75a2e23a65cfb2118cb1",
                "md5": "8277cdc3d66af7d0e339377febc4ca6e",
                "sha256": "3370b3d4065ce2dc5933878c3273f4aea41f945cc6514543b13ad2d57f369ce5"
            },
            "downloads": -1,
            "filename": "skl2onnx-1.16.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8277cdc3d66af7d0e339377febc4ca6e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 925936,
            "upload_time": "2023-12-12T05:49:38",
            "upload_time_iso_8601": "2023-12-12T05:49:38.196157Z",
            "url": "https://files.pythonhosted.org/packages/e9/3f/f624c1d30324597c419006a826ad095345c7457f75a2e23a65cfb2118cb1/skl2onnx-1.16.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-12 05:49:38",
    "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": [
                [
                    ">=",
                    "0.19"
                ]
            ]
        },
        {
            "name": "onnxconverter-common",
            "specs": [
                [
                    ">=",
                    "1.7.0"
                ]
            ]
        }
    ],
    "lcname": "skl2onnx"
}
        
Elapsed time: 0.14477s