Skip to content

BlackBox2C

Convert scikit-learn models to native embedded code — C, C++, Arduino, MicroPython

BlackBox2C converts any trained scikit-learn model into a compact, dependency-free if-else function in your target language — ready to flash on any microcontroller.


Why BlackBox2C?

Most ML deployment tools for embedded systems require a runtime, specific hardware support, or restrict you to certain model types. BlackBox2C takes a different approach:

  • Any scikit-learn model → train with whatever works best (Random Forest, SVM, MLP...)
  • Any target platform → output is pure if-else logic, no runtime needed
  • Exact resource control → tune depth, precision, and memory budget explicitly

Key Features

Feature Description
Universal model support Any scikit-learn estimator with predict()
Multi-format export C, C++11, Arduino, MicroPython
Classification & regression Both task types fully supported
Feature sensitivity analysis Identify and remove unimportant features
Memory budget control Auto-tune parameters to fit a target KB
Zero runtime dependencies Generated code is self-contained

Quick Example

from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_iris
from blackbox2c import convert

iris = load_iris()
model = RandomForestClassifier(n_estimators=50, random_state=42)
model.fit(iris.data, iris.target)

c_code = convert(model, iris.data, max_depth=5)
print(c_code)

See Getting Started for the full walkthrough, or jump straight into the interactive notebooks.


Installation

pip install blackbox2c

Requires Python 3.8+, NumPy >= 1.21, scikit-learn >= 1.0.

Tip: Use a virtual environment: python -m venv .venv && pip install blackbox2c


License

MIT — BlackBox2C Team