sklearn-porter

Repository: https://github.com/nok/sklearn-porter

ExtraTreesClassifier

Documentation: sklearn.ensemble.ExtraTreesClassifier


In [1]:
import sys
sys.path.append('../../../../..')

Load data


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)


((150, 4), (150,))

Train classifier


In [3]:
from sklearn.ensemble import ExtraTreesClassifier

clf = ExtraTreesClassifier(n_estimators=15, random_state=0)
clf.fit(X, y)


Out[3]:
ExtraTreesClassifier(bootstrap=False, class_weight=None, criterion='gini',
           max_depth=None, max_features='auto', max_leaf_nodes=None,
           min_impurity_decrease=0.0, min_impurity_split=None,
           min_samples_leaf=1, min_samples_split=2,
           min_weight_fraction_leaf=0.0, n_estimators=15, n_jobs=None,
           oob_score=False, random_state=0, verbose=0, warm_start=False)

Transpile classifier


In [4]:
from sklearn_porter import Porter

porter = Porter(clf, language='c')
output = porter.export()

print(output)


#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int predict_0(float features[]) {
    int classes[3];
    
    if (features[0] <= 5.521128367517377) {
        if (features[1] <= 2.542369146721012) {
            if (features[2] <= 2.3285940238943343) {
                classes[0] = 1; 
                classes[1] = 0; 
                classes[2] = 0; 
            } else {
                if (features[3] <= 1.4511234333012406) {
                    classes[0] = 0; 
                    classes[1] = 8; 
                    classes[2] = 0; 
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 1; 
                }
            }
        } else {
            if (features[3] <= 0.8387836720096576) {
                classes[0] = 46; 
                classes[1] = 0; 
                classes[2] = 0; 
            } else {
                classes[0] = 0; 
                classes[1] = 3; 
                classes[2] = 0; 
            }
        }
    } else {
        if (features[3] <= 1.8936930649824477) {
            if (features[2] <= 5.1807613674845) {
                if (features[3] <= 0.2542593119501258) {
                    classes[0] = 1; 
                    classes[1] = 0; 
                    classes[2] = 0; 
                } else {
                    if (features[3] <= 1.2979109919829468) {
                        if (features[1] <= 3.1466755002784144) {
                            classes[0] = 0; 
                            classes[1] = 8; 
                            classes[2] = 0; 
                        } else {
                            classes[0] = 2; 
                            classes[1] = 0; 
                            classes[2] = 0; 
                        }
                    } else {
                        if (features[3] <= 1.491774289958074) {
                            classes[0] = 0; 
                            classes[1] = 17; 
                            classes[2] = 0; 
                        } else {
                            if (features[2] <= 4.6486109417083465) {
                                classes[0] = 0; 
                                classes[1] = 7; 
                                classes[2] = 0; 
                            } else {
                                if (features[3] <= 1.7802776400056488) {
                                    if (features[3] <= 1.5065926898187254) {
                                        if (features[2] <= 4.899703297413823) {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        } else {
                                            if (features[2] <= 4.987853350846197) {
                                                classes[0] = 0; 
                                                classes[1] = 2; 
                                                classes[2] = 0; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 2; 
                                            }
                                        }
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 3; 
                                        classes[2] = 0; 
                                    }
                                } else {
                                    if (features[1] <= 3.1244712178243654) {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 5; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 1; 
                                        classes[2] = 0; 
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 8; 
            }
        } else {
            classes[0] = 0; 
            classes[1] = 0; 
            classes[2] = 34; 
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_1(float features[]) {
    int classes[3];
    
    if (features[3] <= 1.550495550183813) {
        if (features[2] <= 2.5923285292922946) {
            classes[0] = 50; 
            classes[1] = 0; 
            classes[2] = 0; 
        } else {
            if (features[0] <= 5.705189773431058) {
                classes[0] = 0; 
                classes[1] = 21; 
                classes[2] = 0; 
            } else {
                if (features[1] <= 2.421156361802088) {
                    if (features[1] <= 2.2376366618358423) {
                        if (features[3] <= 1.0852253511944903) {
                            classes[0] = 0; 
                            classes[1] = 1; 
                            classes[2] = 0; 
                        } else {
                            if (features[2] <= 4.558710343231778) {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            }
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 1; 
                        classes[2] = 0; 
                    }
                } else {
                    if (features[1] <= 2.8877833170885867) {
                        if (features[3] <= 1.2729508337904472) {
                            classes[0] = 0; 
                            classes[1] = 4; 
                            classes[2] = 0; 
                        } else {
                            if (features[0] <= 6.57901134114434) {
                                if (features[2] <= 4.7893806273809885) {
                                    classes[0] = 0; 
                                    classes[1] = 2; 
                                    classes[2] = 0; 
                                } else {
                                    if (features[0] <= 6.121766966716426) {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    } else {
                                        if (features[2] <= 4.916229182751396) {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 1; 
                                        }
                                    }
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 13; 
                        classes[2] = 0; 
                    }
                }
            }
        }
    } else {
        if (features[1] <= 3.173040721499426) {
            if (features[3] <= 2.270621959785941) {
                if (features[0] <= 5.703470148751124) {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 3; 
                } else {
                    if (features[2] <= 5.63718610176714) {
                        if (features[0] <= 6.61522923341691) {
                            if (features[2] <= 5.567684077465091) {
                                if (features[1] <= 2.9151389085288946) {
                                    if (features[0] <= 6.367600776081239) {
                                        if (features[0] <= 6.235229844197272) {
                                            if (features[3] <= 1.652702599886597) {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 3; 
                                            }
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 2; 
                                        }
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    }
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 6; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 3; 
                            }
                        } else {
                            if (features[0] <= 6.718004192936882) {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 2; 
                            }
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 8; 
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 6; 
            }
        } else {
            if (features[3] <= 2.1245702483609095) {
                if (features[3] <= 1.8196133595321136) {
                    if (features[0] <= 6.52049342951073) {
                        classes[0] = 0; 
                        classes[1] = 3; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 1; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 3; 
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 9; 
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_2(float features[]) {
    int classes[3];
    
    if (features[3] <= 1.5465266340960862) {
        if (features[2] <= 4.607131704041432) {
            if (features[2] <= 3.3003282579766613) {
                if (features[3] <= 0.3865875266691616) {
                    classes[0] = 41; 
                    classes[1] = 0; 
                    classes[2] = 0; 
                } else {
                    if (features[2] <= 2.1556475054731816) {
                        classes[0] = 9; 
                        classes[1] = 0; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 3; 
                        classes[2] = 0; 
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 35; 
                classes[2] = 0; 
            }
        } else {
            if (features[1] <= 2.269675323772093) {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 1; 
            } else {
                if (features[2] <= 5.48270001541379) {
                    if (features[2] <= 4.997226012533999) {
                        classes[0] = 0; 
                        classes[1] = 7; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 1; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 1; 
                }
            }
        }
    } else {
        if (features[3] <= 1.6032070119961934) {
            if (features[0] <= 6.518749026326643) {
                classes[0] = 0; 
                classes[1] = 3; 
                classes[2] = 0; 
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 1; 
            }
        } else {
            if (features[3] <= 1.8081436115623295) {
                if (features[1] <= 2.5996223526415174) {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 2; 
                } else {
                    if (features[1] <= 3.026623947930813) {
                        if (features[3] <= 1.7788371596579802) {
                            classes[0] = 0; 
                            classes[1] = 1; 
                            classes[2] = 0; 
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 8; 
                        }
                    } else {
                        if (features[2] <= 5.582715959668016) {
                            if (features[1] <= 3.1452745616104556) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 1; 
                        }
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 34; 
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_3(float features[]) {
    int classes[3];
    
    if (features[0] <= 5.10965102517489) {
        if (features[3] <= 0.34237436990699954) {
            classes[0] = 31; 
            classes[1] = 0; 
            classes[2] = 0; 
        } else {
            if (features[3] <= 0.42014141078495837) {
                classes[0] = 3; 
                classes[1] = 0; 
                classes[2] = 0; 
            } else {
                if (features[1] <= 3.301371923322497) {
                    if (features[2] <= 2.3218753875601132) {
                        classes[0] = 1; 
                        classes[1] = 0; 
                        classes[2] = 0; 
                    } else {
                        if (features[0] <= 4.958256190246744) {
                            if (features[1] <= 2.4726812725055445) {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 3; 
                            classes[2] = 0; 
                        }
                    }
                } else {
                    classes[0] = 1; 
                    classes[1] = 0; 
                    classes[2] = 0; 
                }
            }
        }
    } else {
        if (features[2] <= 5.005993882417837) {
            if (features[3] <= 0.5921558632344295) {
                classes[0] = 14; 
                classes[1] = 0; 
                classes[2] = 0; 
            } else {
                if (features[2] <= 4.886915858549492) {
                    if (features[2] <= 4.584595677776083) {
                        classes[0] = 0; 
                        classes[1] = 32; 
                        classes[2] = 0; 
                    } else {
                        if (features[1] <= 3.0013521708088704) {
                            if (features[0] <= 6.281812153276801) {
                                if (features[3] <= 1.3566014997210807) {
                                    classes[0] = 0; 
                                    classes[1] = 1; 
                                    classes[2] = 0; 
                                } else {
                                    if (features[3] <= 1.4692521397047558) {
                                        classes[0] = 0; 
                                        classes[1] = 2; 
                                        classes[2] = 0; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 2; 
                                    }
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 3; 
                                classes[2] = 0; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 4; 
                            classes[2] = 0; 
                        }
                    }
                } else {
                    if (features[0] <= 6.024789407414449) {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 3; 
                    } else {
                        if (features[3] <= 1.5357312864913262) {
                            classes[0] = 0; 
                            classes[1] = 2; 
                            classes[2] = 0; 
                        } else {
                            if (features[1] <= 2.5827080563561564) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            } else {
                                if (features[0] <= 6.5669079160763015) {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 2; 
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 1; 
                                    classes[2] = 0; 
                                }
                            }
                        }
                    }
                }
            }
        } else {
            if (features[2] <= 5.18632453863042) {
                if (features[1] <= 2.7092082675123628) {
                    if (features[3] <= 1.8776005740851462) {
                        classes[0] = 0; 
                        classes[1] = 1; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 2; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 5; 
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 34; 
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_4(float features[]) {
    int classes[3];
    
    if (features[3] <= 1.3441161325132915) {
        if (features[1] <= 3.0101406622719056) {
            if (features[0] <= 5.551334735276994) {
                if (features[1] <= 2.450468949717688) {
                    if (features[0] <= 5.349339964729427) {
                        if (features[0] <= 4.875015291559983) {
                            classes[0] = 1; 
                            classes[1] = 0; 
                            classes[2] = 0; 
                        } else {
                            classes[0] = 0; 
                            classes[1] = 3; 
                            classes[2] = 0; 
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 3; 
                        classes[2] = 0; 
                    }
                } else {
                    if (features[1] <= 2.854573250447667) {
                        classes[0] = 0; 
                        classes[1] = 3; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 7; 
                        classes[1] = 0; 
                        classes[2] = 0; 
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 19; 
                classes[2] = 0; 
            }
        } else {
            classes[0] = 42; 
            classes[1] = 0; 
            classes[2] = 0; 
        }
    } else {
        if (features[2] <= 4.541221326515648) {
            if (features[3] <= 1.6796973785314397) {
                classes[0] = 0; 
                classes[1] = 10; 
                classes[2] = 0; 
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 1; 
            }
        } else {
            if (features[3] <= 1.8681215891414575) {
                if (features[3] <= 1.7082770221162646) {
                    if (features[2] <= 5.458778541979071) {
                        if (features[1] <= 2.632221823167232) {
                            if (features[1] <= 2.207564135466557) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        } else {
                            if (features[1] <= 2.975065664661111) {
                                if (features[0] <= 6.5700013628279) {
                                    if (features[3] <= 1.4378231510535273) {
                                        classes[0] = 0; 
                                        classes[1] = 1; 
                                        classes[2] = 0; 
                                    } else {
                                        if (features[3] <= 1.5344588928285092) {
                                            if (features[0] <= 6.46420655970892) {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 1; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            }
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        }
                                    }
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 1; 
                                    classes[2] = 0; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 6; 
                                classes[2] = 0; 
                            }
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 2; 
                    }
                } else {
                    if (features[1] <= 2.8407804212030414) {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 3; 
                    } else {
                        if (features[2] <= 6.150836971984635) {
                            if (features[1] <= 3.1337532458575437) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 6; 
                            } else {
                                if (features[2] <= 5.8292593574657765) {
                                    classes[0] = 0; 
                                    classes[1] = 1; 
                                    classes[2] = 0; 
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                }
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 1; 
                        }
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 34; 
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_5(float features[]) {
    int classes[3];
    
    if (features[3] <= 1.7676213332657358) {
        if (features[1] <= 3.4545610617739615) {
            if (features[2] <= 3.650285462161111) {
                if (features[2] <= 3.1891586420402427) {
                    if (features[3] <= 0.9510198136325786) {
                        classes[0] = 28; 
                        classes[1] = 0; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 1; 
                        classes[2] = 0; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 5; 
                    classes[2] = 0; 
                }
            } else {
                if (features[0] <= 5.175535644298231) {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 1; 
                } else {
                    if (features[3] <= 1.453385015240466) {
                        if (features[1] <= 2.6607527474224346) {
                            if (features[3] <= 1.1197721207462903) {
                                classes[0] = 0; 
                                classes[1] = 4; 
                                classes[2] = 0; 
                            } else {
                                if (features[2] <= 5.0340535096243) {
                                    classes[0] = 0; 
                                    classes[1] = 5; 
                                    classes[2] = 0; 
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                }
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 20; 
                            classes[2] = 0; 
                        }
                    } else {
                        if (features[1] <= 3.20006555967917) {
                            if (features[1] <= 2.648931143548773) {
                                if (features[0] <= 6.040335597103385) {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 2; 
                                    classes[2] = 0; 
                                }
                            } else {
                                if (features[0] <= 6.503363661881788) {
                                    if (features[0] <= 5.604512147478798) {
                                        classes[0] = 0; 
                                        classes[1] = 2; 
                                        classes[2] = 0; 
                                    } else {
                                        if (features[3] <= 1.5280856302044936) {
                                            if (features[0] <= 5.985335345919042) {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            } else {
                                                if (features[1] <= 2.835750978598498) {
                                                    if (features[2] <= 4.663137085998029) {
                                                        classes[0] = 0; 
                                                        classes[1] = 1; 
                                                        classes[2] = 0; 
                                                    } else {
                                                        classes[0] = 0; 
                                                        classes[1] = 0; 
                                                        classes[2] = 1; 
                                                    }
                                                } else {
                                                    classes[0] = 0; 
                                                    classes[1] = 2; 
                                                    classes[2] = 0; 
                                                }
                                            }
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        }
                                    }
                                } else {
                                    if (features[1] <= 3.0563716510809584) {
                                        if (features[3] <= 1.6545352601337104) {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 1; 
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        }
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 2; 
                                        classes[2] = 0; 
                                    }
                                }
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 2; 
                            classes[2] = 0; 
                        }
                    }
                }
            }
        } else {
            classes[0] = 22; 
            classes[1] = 0; 
            classes[2] = 0; 
        }
    } else {
        if (features[3] <= 1.8121969431622151) {
            if (features[2] <= 5.562828958622566) {
                if (features[2] <= 4.811849065115006) {
                    if (features[1] <= 3.168442245857255) {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 2; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 1; 
                        classes[2] = 0; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 5; 
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 4; 
            }
        } else {
            classes[0] = 0; 
            classes[1] = 0; 
            classes[2] = 34; 
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_6(float features[]) {
    int classes[3];
    
    if (features[3] <= 1.838072087718473) {
        if (features[3] <= 0.9490862997275972) {
            classes[0] = 50; 
            classes[1] = 0; 
            classes[2] = 0; 
        } else {
            if (features[2] <= 3.9259614145650565) {
                classes[0] = 0; 
                classes[1] = 11; 
                classes[2] = 0; 
            } else {
                if (features[0] <= 5.752439738062188) {
                    if (features[0] <= 5.567584609967886) {
                        if (features[3] <= 1.3096158726185634) {
                            classes[0] = 0; 
                            classes[1] = 3; 
                            classes[2] = 0; 
                        } else {
                            if (features[0] <= 4.996527346128843) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 7; 
                        classes[2] = 0; 
                    }
                } else {
                    if (features[3] <= 1.322621079453789) {
                        classes[0] = 0; 
                        classes[1] = 9; 
                        classes[2] = 0; 
                    } else {
                        if (features[3] <= 1.5331659525110946) {
                            if (features[1] <= 2.9363041020633207) {
                                if (features[1] <= 2.6271371465694107) {
                                    if (features[2] <= 5.213271464880128) {
                                        if (features[0] <= 6.145081779840377) {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 1; 
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 2; 
                                            classes[2] = 0; 
                                        }
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    }
                                } else {
                                    if (features[0] <= 6.104902308906834) {
                                        classes[0] = 0; 
                                        classes[1] = 2; 
                                        classes[2] = 0; 
                                    } else {
                                        if (features[3] <= 1.4576934027935942) {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        } else {
                                            if (features[2] <= 5.0702880434553546) {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 1; 
                                            }
                                        }
                                    }
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 8; 
                                classes[2] = 0; 
                            }
                        } else {
                            if (features[2] <= 5.126040310731612) {
                                if (features[1] <= 3.147003103297744) {
                                    if (features[2] <= 4.807945314997954) {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 2; 
                                    } else {
                                        if (features[0] <= 6.151903292718426) {
                                            if (features[0] <= 6.043046972706338) {
                                                if (features[1] <= 2.9580633267166325) {
                                                    classes[0] = 0; 
                                                    classes[1] = 1; 
                                                    classes[2] = 0; 
                                                } else {
                                                    classes[0] = 0; 
                                                    classes[1] = 0; 
                                                    classes[2] = 1; 
                                                }
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 1; 
                                            }
                                        } else {
                                            if (features[2] <= 4.921195601957272) {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 1; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            }
                                        }
                                    }
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 3; 
                                    classes[2] = 0; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 7; 
                            }
                        }
                    }
                }
            }
        }
    } else {
        classes[0] = 0; 
        classes[1] = 0; 
        classes[2] = 34; 
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_7(float features[]) {
    int classes[3];
    
    if (features[0] <= 4.835077980950054) {
        classes[0] = 16; 
        classes[1] = 0; 
        classes[2] = 0; 
    } else {
        if (features[2] <= 5.052121131706581) {
            if (features[3] <= 1.187984123199987) {
                if (features[2] <= 2.4198502829763324) {
                    classes[0] = 34; 
                    classes[1] = 0; 
                    classes[2] = 0; 
                } else {
                    classes[0] = 0; 
                    classes[1] = 10; 
                    classes[2] = 0; 
                }
            } else {
                if (features[3] <= 1.9700979161064909) {
                    if (features[3] <= 1.2103523333737463) {
                        classes[0] = 0; 
                        classes[1] = 5; 
                        classes[2] = 0; 
                    } else {
                        if (features[3] <= 1.7922824027484205) {
                            if (features[3] <= 1.3556012588196729) {
                                classes[0] = 0; 
                                classes[1] = 13; 
                                classes[2] = 0; 
                            } else {
                                if (features[1] <= 2.350636769926627) {
                                    if (features[2] <= 4.781047702897828) {
                                        classes[0] = 0; 
                                        classes[1] = 1; 
                                        classes[2] = 0; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    }
                                } else {
                                    if (features[0] <= 5.239692497212251) {
                                        if (features[3] <= 1.540099250418558) {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 1; 
                                        }
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 18; 
                                        classes[2] = 0; 
                                    }
                                }
                            }
                        } else {
                            if (features[2] <= 4.8114599180137345) {
                                if (features[0] <= 6.1531159293238975) {
                                    if (features[0] <= 5.917840281026953) {
                                        classes[0] = 0; 
                                        classes[1] = 1; 
                                        classes[2] = 0; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    }
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 3; 
                            }
                        }
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 2; 
                }
            }
        } else {
            if (features[3] <= 1.9630314654063374) {
                if (features[0] <= 6.321498480890744) {
                    if (features[0] <= 5.971857261924007) {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 3; 
                    } else {
                        if (features[1] <= 2.7957859024446297) {
                            if (features[3] <= 1.5647405810243964) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 2; 
                        }
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 8; 
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 27; 
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_8(float features[]) {
    int classes[3];
    
    if (features[2] <= 2.0691016397809667) {
        classes[0] = 50; 
        classes[1] = 0; 
        classes[2] = 0; 
    } else {
        if (features[3] <= 2.2998321977443212) {
            if (features[2] <= 5.756850155334021) {
                if (features[3] <= 1.3336353223788777) {
                    classes[0] = 0; 
                    classes[1] = 28; 
                    classes[2] = 0; 
                } else {
                    if (features[1] <= 2.7958206613730536) {
                        if (features[3] <= 1.6143543486045333) {
                            if (features[2] <= 4.272187437395063) {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            } else {
                                if (features[3] <= 1.407671645533091) {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                } else {
                                    if (features[1] <= 2.4055632554020563) {
                                        if (features[0] <= 6.168692841048085) {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 1; 
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        }
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 2; 
                                        classes[2] = 0; 
                                    }
                                }
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 7; 
                        }
                    } else {
                        if (features[3] <= 2.0267573938538184) {
                            if (features[3] <= 1.6093679712505249) {
                                if (features[2] <= 4.63464527802571) {
                                    classes[0] = 0; 
                                    classes[1] = 10; 
                                    classes[2] = 0; 
                                } else {
                                    if (features[2] <= 4.952073282428859) {
                                        classes[0] = 0; 
                                        classes[1] = 6; 
                                        classes[2] = 0; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    }
                                }
                            } else {
                                if (features[1] <= 2.8720874155782443) {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 2; 
                                } else {
                                    if (features[0] <= 6.517397547539317) {
                                        if (features[1] <= 3.1451728271597688) {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 7; 
                                        } else {
                                            if (features[0] <= 6.105209815576803) {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 1; 
                                            }
                                        }
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 1; 
                                        classes[2] = 0; 
                                    }
                                }
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 5; 
                        }
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 11; 
            }
        } else {
            classes[0] = 0; 
            classes[1] = 0; 
            classes[2] = 14; 
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_9(float features[]) {
    int classes[3];
    
    if (features[2] <= 1.7984751272085284) {
        classes[0] = 48; 
        classes[1] = 0; 
        classes[2] = 0; 
    } else {
        if (features[2] <= 2.743614525085631) {
            classes[0] = 2; 
            classes[1] = 0; 
            classes[2] = 0; 
        } else {
            if (features[3] <= 1.5726279935672078) {
                if (features[1] <= 2.8580128675676453) {
                    if (features[3] <= 1.0071725081685803) {
                        classes[0] = 0; 
                        classes[1] = 7; 
                        classes[2] = 0; 
                    } else {
                        if (features[3] <= 1.4508596346903717) {
                            if (features[0] <= 5.4788470711552755) {
                                classes[0] = 0; 
                                classes[1] = 2; 
                                classes[2] = 0; 
                            } else {
                                if (features[2] <= 4.3105326892188245) {
                                    classes[0] = 0; 
                                    classes[1] = 9; 
                                    classes[2] = 0; 
                                } else {
                                    if (features[3] <= 1.2510118285538396) {
                                        classes[0] = 0; 
                                        classes[1] = 2; 
                                        classes[2] = 0; 
                                    } else {
                                        if (features[3] <= 1.3008071595868549) {
                                            classes[0] = 0; 
                                            classes[1] = 2; 
                                            classes[2] = 0; 
                                        } else {
                                            if (features[1] <= 2.618292793158558) {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 1; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            if (features[2] <= 5.032975637545155) {
                                if (features[2] <= 4.947281997626313) {
                                    classes[0] = 0; 
                                    classes[1] = 3; 
                                    classes[2] = 0; 
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            }
                        }
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 19; 
                    classes[2] = 0; 
                }
            } else {
                if (features[2] <= 6.196690460704703) {
                    if (features[2] <= 5.714549342241243) {
                        if (features[3] <= 1.7483953438728816) {
                            if (features[0] <= 5.124425036935461) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 4; 
                                classes[2] = 0; 
                            }
                        } else {
                            if (features[0] <= 5.9635245683145435) {
                                if (features[1] <= 2.9403134736939704) {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 5; 
                                } else {
                                    if (features[1] <= 3.1597595674715184) {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 1; 
                                        classes[2] = 0; 
                                    }
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 24; 
                            }
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 10; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 6; 
                }
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_10(float features[]) {
    int classes[3];
    
    if (features[0] <= 4.979280319826579) {
        if (features[1] <= 2.4799516418973426) {
            if (features[2] <= 2.1081189544909256) {
                classes[0] = 1; 
                classes[1] = 0; 
                classes[2] = 0; 
            } else {
                classes[0] = 0; 
                classes[1] = 1; 
                classes[2] = 0; 
            }
        } else {
            if (features[2] <= 2.303189077322925) {
                classes[0] = 19; 
                classes[1] = 0; 
                classes[2] = 0; 
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 1; 
            }
        }
    } else {
        if (features[2] <= 4.056690129580384) {
            if (features[2] <= 3.864595594637342) {
                if (features[1] <= 2.4493558386314596) {
                    classes[0] = 0; 
                    classes[1] = 4; 
                    classes[2] = 0; 
                } else {
                    if (features[1] <= 3.1013702094660816) {
                        if (features[0] <= 5.418267413681378) {
                            if (features[1] <= 2.7351736650965983) {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            } else {
                                classes[0] = 1; 
                                classes[1] = 0; 
                                classes[2] = 0; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 2; 
                            classes[2] = 0; 
                        }
                    } else {
                        classes[0] = 29; 
                        classes[1] = 0; 
                        classes[2] = 0; 
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 8; 
                classes[2] = 0; 
            }
        } else {
            if (features[3] <= 2.4500323361484484) {
                if (features[0] <= 7.238129635033258) {
                    if (features[2] <= 4.985589027285003) {
                        if (features[3] <= 1.4175185078836599) {
                            classes[0] = 0; 
                            classes[1] = 19; 
                            classes[2] = 0; 
                        } else {
                            if (features[3] <= 1.9085482831152847) {
                                if (features[3] <= 1.5077226825858063) {
                                    classes[0] = 0; 
                                    classes[1] = 10; 
                                    classes[2] = 0; 
                                } else {
                                    if (features[1] <= 2.8843708444178024) {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 2; 
                                    } else {
                                        if (features[3] <= 1.7559926563657857) {
                                            classes[0] = 0; 
                                            classes[1] = 2; 
                                            classes[2] = 0; 
                                        } else {
                                            if (features[1] <= 3.087776469639185) {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 2; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            }
                                        }
                                    }
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            }
                        }
                    } else {
                        if (features[3] <= 1.9978145065895823) {
                            if (features[3] <= 1.7865760346812085) {
                                if (features[2] <= 5.031112924945041) {
                                    if (features[0] <= 6.33527863763707) {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 1; 
                                        classes[2] = 0; 
                                    }
                                } else {
                                    if (features[3] <= 1.5068336243767517) {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 2; 
                                    } else {
                                        if (features[2] <= 5.787428125717096) {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 1; 
                                        }
                                    }
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 10; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 19; 
                        }
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 8; 
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 3; 
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_11(float features[]) {
    int classes[3];
    
    if (features[1] <= 3.176957139377775) {
        if (features[3] <= 0.653710134740735) {
            classes[0] = 12; 
            classes[1] = 0; 
            classes[2] = 0; 
        } else {
            if (features[3] <= 1.8469214377642704) {
                if (features[2] <= 4.7208371488439) {
                    if (features[0] <= 5.762772968676679) {
                        if (features[3] <= 1.6360344565374696) {
                            classes[0] = 0; 
                            classes[1] = 21; 
                            classes[2] = 0; 
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 1; 
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 19; 
                        classes[2] = 0; 
                    }
                } else {
                    if (features[3] <= 1.7208344558505428) {
                        if (features[2] <= 4.997179626113353) {
                            classes[0] = 0; 
                            classes[1] = 3; 
                            classes[2] = 0; 
                        } else {
                            if (features[0] <= 7.1981562798039125) {
                                if (features[2] <= 5.257435716402731) {
                                    if (features[0] <= 6.436744738593051) {
                                        if (features[0] <= 6.297071906039021) {
                                            if (features[3] <= 1.5681733276103198) {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 1; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            }
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 0; 
                                            classes[2] = 1; 
                                        }
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 1; 
                                        classes[2] = 0; 
                                    }
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            }
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 10; 
                    }
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 22; 
            }
        }
    } else {
        if (features[2] <= 3.8047750384801153) {
            classes[0] = 38; 
            classes[1] = 0; 
            classes[2] = 0; 
        } else {
            if (features[3] <= 2.1793218211052987) {
                if (features[2] <= 5.277179168420336) {
                    if (features[3] <= 1.8542162920413572) {
                        classes[0] = 0; 
                        classes[1] = 5; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 1; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 3; 
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 9; 
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_12(float features[]) {
    int classes[3];
    
    if (features[3] <= 1.7021128663169045) {
        if (features[1] <= 2.9849618599913255) {
            if (features[3] <= 1.4970948166731561) {
                if (features[0] <= 5.623145177587023) {
                    if (features[0] <= 4.779029521813444) {
                        classes[0] = 2; 
                        classes[1] = 0; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 13; 
                        classes[2] = 0; 
                    }
                } else {
                    if (features[3] <= 1.3284118253233357) {
                        classes[0] = 0; 
                        classes[1] = 14; 
                        classes[2] = 0; 
                    } else {
                        if (features[1] <= 2.7629100232801327) {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 1; 
                        } else {
                            classes[0] = 0; 
                            classes[1] = 2; 
                            classes[2] = 0; 
                        }
                    }
                }
            } else {
                if (features[3] <= 1.6376492357878205) {
                    if (features[2] <= 4.602142482827186) {
                        classes[0] = 0; 
                        classes[1] = 3; 
                        classes[2] = 0; 
                    } else {
                        if (features[1] <= 2.7219560941499337) {
                            if (features[0] <= 6.08809298093631) {
                                if (features[3] <= 1.5437156698788206) {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 1; 
                                    classes[2] = 0; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 1; 
                        }
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 1; 
                }
            }
        } else {
            if (features[3] <= 0.6566475003346761) {
                classes[0] = 48; 
                classes[1] = 0; 
                classes[2] = 0; 
            } else {
                if (features[2] <= 5.379769429938613) {
                    classes[0] = 0; 
                    classes[1] = 15; 
                    classes[2] = 0; 
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 1; 
                }
            }
        }
    } else {
        if (features[2] <= 5.2961110038745645) {
            if (features[2] <= 4.819214866434932) {
                if (features[0] <= 6.079608687684341) {
                    if (features[1] <= 3.1799571540756144) {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 1; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 1; 
                        classes[2] = 0; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 1; 
                }
            } else {
                classes[0] = 0; 
                classes[1] = 0; 
                classes[2] = 13; 
            }
        } else {
            classes[0] = 0; 
            classes[1] = 0; 
            classes[2] = 30; 
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_13(float features[]) {
    int classes[3];
    
    if (features[0] <= 7.514114198073155) {
        if (features[1] <= 2.715372280106168) {
            if (features[0] <= 5.046746625449721) {
                if (features[0] <= 4.720041781067867) {
                    classes[0] = 1; 
                    classes[1] = 0; 
                    classes[2] = 0; 
                } else {
                    if (features[2] <= 3.806899171770689) {
                        classes[0] = 0; 
                        classes[1] = 3; 
                        classes[2] = 0; 
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 1; 
                    }
                }
            } else {
                if (features[2] <= 4.904306288471954) {
                    if (features[2] <= 4.623575543578677) {
                        classes[0] = 0; 
                        classes[1] = 16; 
                        classes[2] = 0; 
                    } else {
                        if (features[3] <= 1.786920551746784) {
                            classes[0] = 0; 
                            classes[1] = 1; 
                            classes[2] = 0; 
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 1; 
                        }
                    }
                } else {
                    if (features[0] <= 5.903484684509917) {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 3; 
                    } else {
                        if (features[0] <= 6.0069964788449255) {
                            if (features[2] <= 5.092356647339539) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 4; 
                        }
                    }
                }
            }
        } else {
            if (features[2] <= 3.9028751327869577) {
                if (features[3] <= 0.9294221722708401) {
                    classes[0] = 49; 
                    classes[1] = 0; 
                    classes[2] = 0; 
                } else {
                    classes[0] = 0; 
                    classes[1] = 1; 
                    classes[2] = 0; 
                }
            } else {
                if (features[3] <= 1.95141861134337) {
                    if (features[2] <= 5.92028195024348) {
                        if (features[1] <= 3.033759670573616) {
                            if (features[1] <= 2.9515778790039278) {
                                if (features[3] <= 1.565131126685861) {
                                    if (features[3] <= 1.410602227563526) {
                                        classes[0] = 0; 
                                        classes[1] = 10; 
                                        classes[2] = 0; 
                                    } else {
                                        if (features[1] <= 2.823969189709686) {
                                            if (features[0] <= 6.374041610787189) {
                                                classes[0] = 0; 
                                                classes[1] = 0; 
                                                classes[2] = 1; 
                                            } else {
                                                classes[0] = 0; 
                                                classes[1] = 1; 
                                                classes[2] = 0; 
                                            }
                                        } else {
                                            classes[0] = 0; 
                                            classes[1] = 1; 
                                            classes[2] = 0; 
                                        }
                                    }
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 2; 
                                }
                            } else {
                                if (features[3] <= 1.7349329909051114) {
                                    if (features[2] <= 5.507388994961175) {
                                        classes[0] = 0; 
                                        classes[1] = 8; 
                                        classes[2] = 0; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    }
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 4; 
                                }
                            }
                        } else {
                            if (features[1] <= 3.2667907396292932) {
                                if (features[0] <= 6.851033190025923) {
                                    if (features[2] <= 5.3080841532160195) {
                                        classes[0] = 0; 
                                        classes[1] = 4; 
                                        classes[2] = 0; 
                                    } else {
                                        classes[0] = 0; 
                                        classes[1] = 0; 
                                        classes[2] = 1; 
                                    }
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 2; 
                                    classes[2] = 0; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 2; 
                                classes[2] = 0; 
                            }
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 3; 
                    }
                } else {
                    classes[0] = 0; 
                    classes[1] = 0; 
                    classes[2] = 22; 
                }
            }
        }
    } else {
        classes[0] = 0; 
        classes[1] = 0; 
        classes[2] = 6; 
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict_14(float features[]) {
    int classes[3];
    
    if (features[2] <= 1.5213681480470247) {
        classes[0] = 37; 
        classes[1] = 0; 
        classes[2] = 0; 
    } else {
        if (features[2] <= 3.37330671523965) {
            if (features[2] <= 1.928483210061239) {
                classes[0] = 13; 
                classes[1] = 0; 
                classes[2] = 0; 
            } else {
                classes[0] = 0; 
                classes[1] = 3; 
                classes[2] = 0; 
            }
        } else {
            if (features[3] <= 1.4203844512442054) {
                if (features[0] <= 5.271800297439006) {
                    classes[0] = 0; 
                    classes[1] = 2; 
                    classes[2] = 0; 
                } else {
                    if (features[3] <= 1.39844428030661) {
                        classes[0] = 0; 
                        classes[1] = 24; 
                        classes[2] = 0; 
                    } else {
                        if (features[1] <= 2.815819690150918) {
                            if (features[0] <= 6.575260628582079) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 1; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 5; 
                            classes[2] = 0; 
                        }
                    }
                }
            } else {
                if (features[2] <= 5.073323222996153) {
                    if (features[2] <= 4.727728304418108) {
                        if (features[3] <= 1.683098307870985) {
                            classes[0] = 0; 
                            classes[1] = 10; 
                            classes[2] = 0; 
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 1; 
                        }
                    } else {
                        if (features[3] <= 1.7955400567946675) {
                            if (features[2] <= 4.922632110478459) {
                                classes[0] = 0; 
                                classes[1] = 2; 
                                classes[2] = 0; 
                            } else {
                                if (features[1] <= 2.547516165983607) {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 1; 
                                    classes[2] = 0; 
                                }
                            }
                        } else {
                            if (features[1] <= 3.0302843343947554) {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 7; 
                            } else {
                                classes[0] = 0; 
                                classes[1] = 1; 
                                classes[2] = 0; 
                            }
                        }
                    }
                } else {
                    if (features[1] <= 3.110966564102843) {
                        if (features[3] <= 1.8737745337319733) {
                            if (features[0] <= 6.175840054744521) {
                                if (features[0] <= 5.9332085107091395) {
                                    classes[0] = 0; 
                                    classes[1] = 0; 
                                    classes[2] = 1; 
                                } else {
                                    classes[0] = 0; 
                                    classes[1] = 1; 
                                    classes[2] = 0; 
                                }
                            } else {
                                classes[0] = 0; 
                                classes[1] = 0; 
                                classes[2] = 7; 
                            }
                        } else {
                            classes[0] = 0; 
                            classes[1] = 0; 
                            classes[2] = 19; 
                        }
                    } else {
                        classes[0] = 0; 
                        classes[1] = 0; 
                        classes[2] = 13; 
                    }
                }
            }
        }
    }
    int class_idx = 0;
    int class_val = classes[0];
    int i;
    for (i = 1; i < 3; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int predict (float features[]) {
    int n_classes = 3;
    int classes[n_classes];
    int i;
    for (i = 0; i < n_classes; i++) {
        classes[i] = 0;
    }

    classes[predict_0(features)]++;
    classes[predict_1(features)]++;
    classes[predict_2(features)]++;
    classes[predict_3(features)]++;
    classes[predict_4(features)]++;
    classes[predict_5(features)]++;
    classes[predict_6(features)]++;
    classes[predict_7(features)]++;
    classes[predict_8(features)]++;
    classes[predict_9(features)]++;
    classes[predict_10(features)]++;
    classes[predict_11(features)]++;
    classes[predict_12(features)]++;
    classes[predict_13(features)]++;
    classes[predict_14(features)]++;

    int class_idx = 0;
    int class_val = classes[0];
    for (i = 1; i < n_classes; i++) {
        if (classes[i] > class_val) {
            class_idx = i;
            class_val = classes[i];
        }
    }
    return class_idx;
}

int main(int argc, const char * argv[]) {
    float features[argc-1];
    int i;
    for (i = 1; i < argc; i++) {
        features[i-1] = atof(argv[i]);
    }
    printf("%d", predict(features));
    return 0;
}

Run classification in C


In [5]:
# Save model:
# with open('forest.c', 'w') as f:
#     f.write(output)

# Compile model:
# $ gcc forest.c -std=c99 -lm -o forest

# Run classification:
# $ ./forest 1 2 3 4