sklearn2c


Namesklearn2c JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryA simple tool to embed scikit-learn models into microcontrollers
upload_time2024-06-16 18:47:51
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6
licenseMIT License Copyright (c) 2022 EmbeddedML Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords embedded machine learning scikit-learn
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Machine Learning for Embbedded Devices
sklearn2c is a tool that converts scikit-learn library classification algorithms to C code. It can be used to generate C code from trained models, which can then be used in microcontrollers or other embedded systems. The generated code can be used for real-time classification tasks, where the computational resources are limited.

## Supported Models
### Classification
- Bayes Classifier*
- Decision Trees
- KNN Classifier
- C-SVC**
  
  *: sklearn2c does not use scikit-learn `GaussianNB()`, instead it uses the following cases to compute decision function.
  
  **: `linear`, `poly` and `rbf` kernels are supported.
### Regression
- Linear Regression
- Polynomial Regression
- KNN
- Decision Trees
### Clustering
- kmeans
- DBSCAN

## Installation
You can install the library via pip either using:

`pip install sklearn2c`

or

`pip install git+git@github.com:EmbeddedML/sklearn2c.git`

Alternatively, you can install conda package:

`conda install sklearn2c` or `mamba install sklearn2c`

## Usage

Please check `examples` directory under this repository. For example, decision tree classifier is created as follows:
- `train` method trains the model and optionally saves the model file to `save_path`. This method is totally compatible with scikit-learn library. 
- `predict` method runs the model on the given data.
- static method `load` loads the model from saved path.
- `export` method generates model parameters as C functions.

```
dtc = DTClassifier()
dtc.train(train_samples, train_labels, save_path="<path/to/model>")
dtc.predict(test_samples)
dtc2 = DTClassifier.load(dtc_model_dir)
dtc2.export("<path/to/config_dir>")
```
For inference on C(specifically for STM32 boards), you can take a look at `STM32_inference` directory for the corresponding model.

## License
[MIT](LICENSE)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sklearn2c",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "EmbeddedML <berkanh@gmail.com>",
    "keywords": "embedded, machine learning, scikit-learn",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/38/d6/6b5169226f64b593d849cf242170c8233c52f68d2644131cc09804c88d40/sklearn2c-0.0.2.tar.gz",
    "platform": null,
    "description": "# Machine Learning for Embbedded Devices\r\nsklearn2c is a tool that converts scikit-learn library classification algorithms to C code. It can be used to generate C code from trained models, which can then be used in microcontrollers or other embedded systems. The generated code can be used for real-time classification tasks, where the computational resources are limited.\r\n\r\n## Supported Models\r\n### Classification\r\n- Bayes Classifier*\r\n- Decision Trees\r\n- KNN Classifier\r\n- C-SVC**\r\n  \r\n  *: sklearn2c does not use scikit-learn `GaussianNB()`, instead it uses the following cases to compute decision function.\r\n  \r\n  **: `linear`, `poly` and `rbf` kernels are supported.\r\n### Regression\r\n- Linear Regression\r\n- Polynomial Regression\r\n- KNN\r\n- Decision Trees\r\n### Clustering\r\n- kmeans\r\n- DBSCAN\r\n\r\n## Installation\r\nYou can install the library via pip either using:\r\n\r\n`pip install sklearn2c`\r\n\r\nor\r\n\r\n`pip install git+git@github.com:EmbeddedML/sklearn2c.git`\r\n\r\nAlternatively, you can install conda package:\r\n\r\n`conda install sklearn2c` or `mamba install sklearn2c`\r\n\r\n## Usage\r\n\r\nPlease check `examples` directory under this repository. For example, decision tree classifier is created as follows:\r\n- `train` method trains the model and optionally saves the model file to `save_path`. This method is totally compatible with scikit-learn library. \r\n- `predict` method runs the model on the given data.\r\n- static method `load` loads the model from saved path.\r\n- `export` method generates model parameters as C functions.\r\n\r\n```\r\ndtc = DTClassifier()\r\ndtc.train(train_samples, train_labels, save_path=\"<path/to/model>\")\r\ndtc.predict(test_samples)\r\ndtc2 = DTClassifier.load(dtc_model_dir)\r\ndtc2.export(\"<path/to/config_dir>\")\r\n```\r\nFor inference on C(specifically for STM32 boards), you can take a look at `STM32_inference` directory for the corresponding model.\r\n\r\n## License\r\n[MIT](LICENSE)\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2022 EmbeddedML  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A simple tool to embed scikit-learn models into microcontrollers",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/EmbeddedML/sklearn2c",
        "Issue Tracker": "https://github.com/EmbeddedML/sklearn2c/issues/"
    },
    "split_keywords": [
        "embedded",
        " machine learning",
        " scikit-learn"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "779a9eed7e65e91e0f67a53538aac75419e71356f3c01e021f2a48d3c25083f8",
                "md5": "4b8f4df888b7cf2f6c4d069cf3bdbbf3",
                "sha256": "3d23bff3a3d39aeafdeb4d2335588126b0eef5a67ac8be272bd262dbb775f68c"
            },
            "downloads": -1,
            "filename": "sklearn2c-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4b8f4df888b7cf2f6c4d069cf3bdbbf3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 17611,
            "upload_time": "2024-06-16T18:47:49",
            "upload_time_iso_8601": "2024-06-16T18:47:49.824776Z",
            "url": "https://files.pythonhosted.org/packages/77/9a/9eed7e65e91e0f67a53538aac75419e71356f3c01e021f2a48d3c25083f8/sklearn2c-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38d66b5169226f64b593d849cf242170c8233c52f68d2644131cc09804c88d40",
                "md5": "6bd33a770490dc5b39c5d76f93cd030a",
                "sha256": "f8ad5c65568f13734ffc0a42d18d7d2214aa87768405c84b7b44f15d36f173de"
            },
            "downloads": -1,
            "filename": "sklearn2c-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "6bd33a770490dc5b39c5d76f93cd030a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 11437,
            "upload_time": "2024-06-16T18:47:51",
            "upload_time_iso_8601": "2024-06-16T18:47:51.369081Z",
            "url": "https://files.pythonhosted.org/packages/38/d6/6b5169226f64b593d849cf242170c8233c52f68d2644131cc09804c88d40/sklearn2c-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-16 18:47:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "EmbeddedML",
    "github_project": "sklearn2c",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "sklearn2c"
}
        
Elapsed time: 0.27548s