Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Tree-based machine learning for embedded system

Project description

emtrees

Tree-based machine learning classifiers for embedded systems. Train in Python, deploy on microcontroller.

Want Naive Bayes instead? Go to embayes

Key features

Embedded-friendly Classifier

  • Portable C99 code
  • No stdlib required
  • No dynamic allocations
  • Integer/fixed-point math only
  • Single header file include
  • Fast, sub-millisecond classification

Convenient Training

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

MIT licensed

Status

Minimally useful

  • Random Forests and ExtraTrees classifiers implemented
  • Tested running on AVR, 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

1.0

  • Support returning probabilities
  • Support serializing/deserializing trees

Maybe

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

Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
emtrees-0.2.3.tar.gz (5.6 kB) Copy SHA256 hash SHA256 Source None May 26, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page