Skip to main content

A simple tool to embed scikit-learn models into microcontrollers

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sklearn2c-0.0.3.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sklearn2c-0.0.3-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file sklearn2c-0.0.3.tar.gz.

File metadata

  • Download URL: sklearn2c-0.0.3.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.18

File hashes

Hashes for sklearn2c-0.0.3.tar.gz
Algorithm Hash digest
SHA256 35ce4278314f0a5eda1624aad191824f0f58c7c6db1b278c64a5f351b39d8e29
MD5 515ec0c8ca9d733716515f8f5178f9ea
BLAKE2b-256 145c832737a9cda8cd75865e973edb0c042a40206e6b9783107acf1523e0b441

See more details on using hashes here.

File details

Details for the file sklearn2c-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: sklearn2c-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.18

File hashes

Hashes for sklearn2c-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a73346f5e3208492f7f6d1eec04b05ef4d64dd07fb0d84b622defae0c1a79b23
MD5 96c8dff4ae46857ce405aa5807d61027
BLAKE2b-256 ef14bd1340de60f25de1c68fc317f5fd5879bde72ef9a5c9928a370c07e8dfc3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page