Repository: https://github.com/nok/sklearn-porter
Documentation: sklearn.tree.DecisionTreeClassifier
In [1]:
import sys
sys.path.append('../../../../..')
In [2]:
from sklearn.datasets import load_iris
iris_data = load_iris()
X = iris_data.data
y = iris_data.target
print(X.shape, y.shape)
In [3]:
from sklearn.tree import tree
clf = tree.DecisionTreeClassifier()
clf.fit(X, y)
Out[3]:
In [4]:
from sklearn_porter import Porter
porter = Porter(clf, language='c')
output = porter.export(embed_data=True)
print(output)
In [5]:
# Save model:
# with open('tree.c', 'w') as f:
# f.write(output)
# Compile model:
# $ gcc tree.c -std=c99 -lm -o tree
# Run classification:
# $ ./tree 1 2 3 4