<jupyter_start><jupyter_text>sklearn-porterRepository: https://github.com/nok/sklearn-porter RandomForestClassifierDocumentation: [sklearn.ensemble.RandomForestClassifier](http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html)  Loading data:<jupyter_code>from sklearn.datasets import load_iris

iris_data = load_iris()
X = iris_data.data
y = iris_data.target

print(X.shape, y.shape)<jupyter_output>((150, 4), (150,))<jupyter_text>Train classifier:<jupyter_code>from sklearn.ensemble import RandomForestClassifier

clf = RandomForestClassifier(n_estimators=15, max_depth=None,
                             min_samples_split=2, random_state=0)
clf.fit(X, y)<jupyter_output><empty_output><jupyter_text>Transpile classifier:<jupyter_code>%%time

from sklearn_porter import Porter

porter = Porter(clf)
output = porter.export(embed_data=True)

print(output)<jupyter_output>class RandomForestClassifier {
    public static int predict_0(double[] features) {
        int[] classes = new int[3];
        
        if (features[3] <= 0.75) {
            classes[0] = 47; 
            classes[1] = 0; 
            classes[2] = 0; 
        } else {
            if (features[2] <= 4.85000038147) {
                if (features[3] <= 1.65000009537) {
                    classes[0] = 0; 
                    classes[1] = 42; 
                    classes[2] = 0; 
                } else {
                    if (features[1] <= 3.0) {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 3; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 1; 
                        classes[2] = 0; 
                    }
                }
            } else {
                if (features[0] <= 6.59999990463) {
                    classes[0] = 0; 
                    cla[...]<jupyter_text>Run classification in Java: Save the transpiled estimator:<jupyter_code>with open('RandomForestClassifier.java', 'w') as f:
    f.write(output)<jupyter_output><empty_output><jupyter_text>Compiling:<jupyter_code>%%bash

javac -cp . RandomForestClassifier.java<jupyter_output><empty_output><jupyter_text>Prediction:<jupyter_code>%%bash

java -cp . RandomForestClassifier 1 2 3 4<jupyter_output>1
{'fraction_non_alphanumeric': 0.11546747091770788, 'fraction_numerical': 0.03963808703145196, 'mean_word_length': 2.202758620689655, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 22, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '599543', 'license': 'MIT', 'n_tokens_mistral': 843, 'n_tokens_neox': 746, 'n_words': 118, 'path': 'examples/estimator/classifier/RandomForestClassifier/java/basics_embedded.ipynb', 'repo_name': 'mathewdgardner/sklearn-porter', 'size': '2321'}