Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.
/ micromlgen Public archive

Generate C code for microcontrollers from Python's sklearn classifiers

License

Notifications You must be signed in to change notification settings

agrimagsrl/micromlgen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introducing MicroML

MicroML is an attempt to bring Machine Learning algorithms to microcontrollers. Please refer to this blog post to an introduction to the topic.

Install

pip install micromlgen

Use

from micromlgen import port
from sklearn.svm import SVC
from sklearn.datasets import load_iris


if __name__ == '__main__':
    iris = load_iris()
    X = iris.data
    y = iris.target
    clf = SVC(kernel='linear').fit(X, y)
    print(port(clf))

You may pass a classmap to get readable class names in the ported code

from micromlgen import port
from sklearn.svm import SVC
from sklearn.datasets import load_iris


if __name__ == '__main__':
    iris = load_iris()
    X = iris.data
    y = iris.target
    clf = SVC(kernel='linear').fit(X, y)
    print(port(clf, classmap={
        0: 'setosa',
        1: 'virginica',
        2: 'versicolor'
    }))

You can pass a test set to generate self test code

from micromlgen import port
from sklearn.svm import SVC
from sklearn.datasets import load_iris


if __name__ == '__main__':
    iris = load_iris()
    X_train, X_test = iris.data[:-10, :], iris.data[-10:, :]
    y_train, y_test = iris.target[:-10], iris.target[-10:]
    clf = SVC(kernel='linear').fit(X_train, y_train)
    print(port(clf, test_set=(X_test, y_test)))