Package: twigy
This repository contains a C++ implementation of the CART algorithm (currently, only supporting classification), offering a similar API for decision trees and random forests as thesklearnimplementation. In addition to the C++ library, the python packagetwigyoffers python bindings for the main user facing classes.twigyGetting Started1. Use pip installpip install twigy2. Build manylinux wheel from sourceThe manylinux wheel is build in a CentOS 7 docker container, so you need to have docker installed. Then run./build_manylinux_wheel.shwhich will build the manylinux wheel. Then you canpip install ./build/wheelhouse/twigy-0.0.1-cp36-cp36m-manylinux2014_x86_64.whl3. Build extension library from sourceTo directly build the python extension library, you need cmake >= 3.10 and boost >= 1.66 on your system.cd ./build && cmake ..cmake --build . --target twigyDecisionTreeClassifierImplements a CART decision tree classifier. See also./example.pyfor usage.Parametersimpurity_measuresets the measure of impurity used for the splits. Takestwigy.ImpurityMeasure.giniortwigy.ImpurityMeasure.gini. Default istwigy.ImpurityMeasure.gini.max_depthsets the maximum depth to which the tree is grown. Default is-1,  which corresponds to no restriction on the depth.min_samples_splitsets the minimum number of samples for a node to be split. Default is2.min_samples_leafsets the minimum number of samples at a leaf node. Split that would lead to a lower number are not considered. Default is1.max_featuressets the maximum number of randomly selected features to be considered at each split. Default is-1, which corresponds chosing the number of features accoding to themax_features_method.max_features_methodsets the method by which the number of features to be considerd at each split is chosen unless it is explicitly specified bymax_features. Possible valuetwigy.MaxFeaturesMethod.sqrt_method,twigy.MaxFeaturesMethod.log2_methodandtwigy.MaxFeaturesMethod.all_method. Default istwigy.MaxFeaturesMethod.all_method.min_impurity_splitsets the minimal impurity for a node to be considered for another split. Default is0.0.Methodsbuild_tree(X, y)grows the tree on the training set given by the featuresXand the labelsy. Note that the class labels need to be given by0,1,2,..., n_classes - 1.print_tree()print a list of the nodes of the decision tree.predict_classes(X)predicts the class labels for the given samplesX.RandomForestClassifierImplements a random forest classifier. See also./example.pyfor usage.Parametersn_estimatorssets the number of decision tree estimators to train.impurity_measuresets the measure of impurity used for the splits. Takestwigy.ImpurityMeasure.giniortwigy.ImpurityMeasure.gini. Default istwigy.ImpurityMeasure.gini.max_depthsets the maximum depth to which the tree is grown. Default is-1,  which corresponds to no restriction on the depth.min_samples_splitsets the minimum number of samples for a node to be split. Default is2.min_samples_leafsets the minimum number of samples at a leaf node. Split that would lead to a lower number are not considered. Default is1.max_featuressets the maximum number of randomly selected features to be considered at each split. Default is-1, which corresponds chosing the number of features accoding to themax_features_method.max_features_methodsets the method by which the number of features to be considerd at each split is chosen unless it is explicitly specified bymax_features. Possible valuetwigy.MaxFeaturesMethod.sqrt_method,twigy.MaxFeaturesMethod.log2_methodandtwigy.MaxFeaturesMethod.all_method. Default istwigy.MaxFeaturesMethod.sqrt_method(note that the default is different that for theDecisionTreeClassifier).min_impurity_splitsets the minimal impurity for a node to be considered for another split. Default is0.0.max_samplessets the number of randomly selected samples to be used to train the individual trees. Default is-1, which corresponds to all samples being used for each tree.Methodsbuild_forest(X, y)trains the random forest on the training set given by the featuresXand the labelsy. Note that the class labels need to be given by0,1,2,..., n_classes - 1.predict_classes(X)predicts the class labels for the given samplesX.Benchmarktwigy has been benchmarked (on an i3-7100 CPU @ 3.90 with 16GB memory) against scikit learn:The benchmark shows that twigy is up to 8 times faster on this dataset. For more details seebenchmark.py.C++ librarytwigy can also be used as c++ library as illustrated inexample.cpp.Build cpp example from sourceTo build the example you need cmake >= 3.10 and boost >= 1.66 on your system. Then runcd ./build && cmake ..cmake --build . --target example