nok / sklearn-porter

Transpile trained scikit-learn estimators to C, Java, JavaScript and others.
BSD 3-Clause "New" or "Revised" License
1.28k stars 170 forks source link

Invalid java generated for random forrest #59

Closed markusheiden closed 2 years ago

markusheiden commented 4 years ago

There are several compile errors when transpiling random forrests to java:

Maybe there are other errors too, because the transpiled random forrest does not produce the same result as python.

nok commented 4 years ago

Thanks for your feedback, but I can't reproduce your critical issues. Can you install the latest version of release/1.0.0 and test it again please?

pip install https://github.com/nok/sklearn-porter/zipball/release/1.0.0

Here is a basic example:

from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

from sklearn_porter import Estimator

# 1. Load data and train a dummy classifier:
X, y = load_iris(return_X_y=True)
clf = RandomForestClassifier()
clf.fit(X, y)

# 2. Port or transpile an estimator:
est = Estimator(clf, language='java', template='exported')

# output = est.port()
# print(output)

# 3. Validate and compare the predictions:
score = est.test(X)
print(score)  # the score should be 1.0

https://github.com/nok/sklearn-porter/tree/release/1.0.0#basics