Metadata-Version: 2.1
Name: sklearn2c
Version: 0.0.2
Summary: A simple tool to embed scikit-learn models into microcontrollers
Maintainer-email: EmbeddedML <berkanh@gmail.com>
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.
        
Project-URL: Homepage, https://github.com/EmbeddedML/sklearn2c
Project-URL: Issue Tracker, https://github.com/EmbeddedML/sklearn2c/issues/
Keywords: embedded,machine learning,scikit-learn
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: scikit-learn
Requires-Dist: numpy

# 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)

