<jupyter_start><jupyter_text>sklearn-porterRepository: https://github.com/nok/sklearn-porter AdaBoostClassifierDocumentation: [sklearn.ensemble.AdaBoostClassifier](http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.AdaBoostClassifier.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 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)<jupyter_output><empty_output><jupyter_text>Transpile classifier:<jupyter_code>%%time

from sklearn_porter import Porter

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

print(output)<jupyter_output>class AdaBoostClassifier {

    private static int findMax(double[] nums) {
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            index = nums[i] > nums[index] ? i : index;
        }
        return index;
    }
    
    private static double[] predict_0(double[] features) {
        double[] classes = new double[3];
        if (features[3] <= 0.800000011921) {
            classes[0] = 0.333333333333; 
            classes[1] = 0.0; 
            classes[2] = 0.0; 
        } else {
            if (features[3] <= 1.75) {
                if (features[2] <= 4.94999980927) {
                    if (features[3] <= 1.65000009537) {
                        classes[0] = 0.0; 
                        classes[1] = 0.313333333333; 
                        classes[2] = 0.0; 
                    } else {
                        classes[0] = 0.0; 
                        classes[1] = 0.0; 
                        classes[2] = 0.00666666666667; 
                    }
        [...]<jupyter_text>Run classification in Java: Save the estimator:<jupyter_code>with open('AdaBoostClassifier.java', 'w') as f:
    f.write(output)<jupyter_output><empty_output><jupyter_text>Compiling:<jupyter_code>%%bash

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

java AdaBoostClassifier 1 2 3 4<jupyter_output>2
{'fraction_non_alphanumeric': 0.11881606765327696, 'fraction_numerical': 0.054122621564482026, 'mean_word_length': 2.725984251968504, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, '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': '382655', 'license': 'MIT', 'n_tokens_mistral': 920, 'n_tokens_neox': 800, 'n_words': 131, 'path': 'examples/estimator/classifier/AdaBoostClassifier/java/basics_embedded.ipynb', 'repo_name': 'mathewdgardner/sklearn-porter', 'size': '2365'}