Repository: https://github.com/nok/sklearn-porter
Documentation: sklearn.ensemble.AdaBoostClassifier
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 AdaBoostClassifier
from sklearn.tree import DecisionTreeClassifier
base_estimator = DecisionTreeClassifier(max_depth=4, random_state=0)
clf = AdaBoostClassifier(base_estimator=base_estimator, n_estimators=100,
random_state=0)
clf.fit(X, y)
Out[3]:
In [4]:
from sklearn_porter import Porter
porter = Porter(clf, language='js')
output = porter.export(export_data=True)
print(output)
In [5]:
# Save classifier:
# with open('AdaBoostClassifier.js', 'w') as f:
# f.write(output)
# Check model data:
# $ cat data.json
# Run classification:
# if hash node 2/dev/null; then
# python -m SimpleHTTPServer 8877 & serve_pid=$!
# node AdaBoostClassifier.js http://127.0.0.1:8877/data.json 1 2 3 4
# kill $serve_pid
# fi