Repository: https://github.com/nok/sklearn-porter
Documentation: sklearn.ensemble.ExtraTreesClassifier
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.ensemble import ExtraTreesClassifier
clf = ExtraTreesClassifier(n_estimators=15, random_state=0)
clf.fit(X, y)
Out[3]:
In [4]:
from sklearn_porter import Porter
porter = Porter(clf, language='java')
output = porter.export(export_data=True)
print(output)
In [5]:
# Save classifier:
# with open('ExtraTreesClassifier.java', 'w') as f:
# f.write(output)
# Check model data:
# $ cat data.json
# Download dependencies:
# $ wget -O gson.jar http://central.maven.org/maven2/com/google/code/gson/gson/2.8.5/gson-2.8.5.jar
# Compile model:
# $ javac -cp .:gson.jar ExtraTreesClassifier.java
# Run classification:
# $ java -cp .:gson.jar ExtraTreesClassifier data.json 1 2 3 4