Skip to main content

emtrees

Tree-based machine learning classifiers for microcontroller and embedded systems. Train in Python, then do inference on any device with support for C.

Want Naive Bayes instead? Go to embayes

Key features

Embedded-friendly Inference

  • Portable C99 code
  • No libc required
  • No dynamic allocations
  • Integer/fixed-point math only
  • Single header file include
  • Fast, sub-millisecond classification
  • Memory efficient. Can run with <100 bytes RAM

Convenient Training

  • API-compatible with scikit-learn
  • Implemented in Python 3
  • C classifier accessible in Python using pybind11

MIT licensed

Can be used as an open source alternative to MATLAB Classification Trees, Decision Trees using MATLAB Coder for C/C++ code generation. fitctree, fitcensemble, TreeBagger, ClassificationEnsemble, CompactTreeBagger

Status

Minimally useful

  • Random Forests and ExtraTrees classifiers implemented
  • Tested running on AVR Atmega, ESP8266 and Linux.
  • On ESP8266, 8x8 digits classify in under 0.3ms with 95%+ accuracy
  • On Linux, is approx 2x faster than sklearn

Installing

Install from PyPI

pip install emtrees --user

Usage

  1. Train your model in Python
import emtrees
estimator = emtrees.RandomForest(n_estimators=10, max_depth=10)
estimator.fit(X_train, Y_train)
...
  1. Generate C code
code = estimator.output_c('sonar')
with open('sonar.h', 'w') as f:
   f.write(code)
  1. Use the C code
#include <emtrees.h>
#include "sonar.h"

const int32_t length = 60;
int32_t values[length] = { ... };
const int32_t predicted_class = sonar_predict(values, length):

For full example code, see examples/digits.py and emtrees.ino

TODO

0.2

  • Standalone example application on microcontroller
  • Include emtrees.h inline in generated code

1.0

  • Support returning probabilities
  • Support serializing/deserializing trees

Probably

  • Support sklearn GradientBoostingClassifier
  • Support regression trees
  • Support weighted voting
  • Implement Isolation Forests (requires path/depths)

Maybe

  • Support XGBoost learning of trees
  • Support LightGBM learning of trees
  • Support CatBoost learning of trees
  • Support/Implement a Very Fast Decision Tree (VFDT) learning algorithm
  • Implement multithreading when used in Python bindings, using OpenMP

Metadata

Release files for emtrees 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for emtrees 0.2.5
File Size Uploaded
emtrees-0.2.5.tar.gz 13.6 kB Details

Release files / emtrees-0.2.5.tar.gz

Download URL emtrees-0.2.5.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
037e7a9b7b6f21aefb8e5e8d00863414d4784d4a9755d6278dab2390e3c7e916
BLAKE2b-256 checksum
How to use checksums
6417f1fcf11fde45023e787d271df0a1c5c890a887e7dcdabd3c646b40765ead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.3

Release history Release notifications | RSS feed

This release

0.2.5 This release

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.1

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page