Package: treefarms
Exploring the Whole Rashomon Set of Sparse Decision Trees (TreeFARMS)This code createsRashomon setsof decision trees. The Rashomon set is the set of all almost-optimal models. This code is able to enumerate the Rashomon set for sparse decision trees. In other words, instead of returning a single optimal decision tree, it returns a set of decision trees with an objective (misclassification loss with a penalty on the number of leaves) below a pre-defined threshold. To learn more about TreeFARMS, please read ourresearch paper(published at NeurIPS'22).Given the Rashomon set enumerated by this code, an interactive toolTimberTrekcan be used to visualize and explore this set of trees.To make TreeFARMS run faster, please use the options to limit the depth of the tree, and increase the regularization parameter above 0.02. If you run the algorithm without a depth constraint or set the regularization too small, it will run more slowly.TreeFARMS builds on a number of innovations for scalable construction of optimal tree-based classifiers: Scalable Bayesian Rule Lists[8], CORELS[2], OSDT[4], and, most closely, GOSDT[5].Note: this repository is built based onFast Sparse Decision Tree Optimization via Reference Ensembles. Package is renamed to allow the installation of both packages. In this repository, all references to GOSDT refers TreeFARMS algorithm.Table of ContentInstallationCompilationConfigurationExampleRepository StructureLicenseFAQsInstallationYou may use the following commands to install TreeFARMS along with its dependencies on macOS, Ubuntu and Windows.You needPython 3.7 or laterto use the moduletreefarmsin your project. If you encountered an errorERROR: Could not find a version that satisfies the requirement treefarms, try updating your pip to the latest version.pip3installattrspackagingeditablespandasscikit-learnsortedcontainersgmpy2matplotlib
pip3installtreefarmsYou can find a list of available wheels onPyPI.Please feel free to open an issue if you do not see your distribution offered.CompilationPlease refer to themanualto build the C++ command line interface and the Python extension module and run the experiment with example datasets on your machine.ConfigurationThe configuration is a JSON object and has the following structure and default values:{"regularization":0.05,"rashomon":true,"rashomon_bound_multiplier":0.05,"rashomon_bound":0,"rashomon_bound_adder":0,"output_accuracy_model_set":false,"output_covered_sets":[],"covered_sets_thresholds":[],"rashomon_model_set_suffix":"","rashomon_ignore_trivial_extensions":true,"rashomon_trie":"","depth_budget":0,"uncertainty_tolerance":0.0,"upperbound":0.0,"precision_limit":0,"stack_limit":0,"tile_limit":0,"time_limit":0,"worker_limit":1,"minimum_captured_points":0,"cancellation":true,"look_ahead":true,"diagnostics":false,"verbose":true,"costs":"","model":"","profile":"","timing":"","trace":"","tree":"","datatset_encoding":"","memory_checkpoints":[],}Key parametersregularizationValues: Decimal within range [0,1]Description: Used to penalize complexity. A complexity penalty is added to the risk in the following way.ComplexityPenalty = # Leaves x regularizationDefault: 0.05Note: We highly recommend setting the regularization to a value larger than 1/num_samples. A small regularization could lead to a longer training time. If a smaller regularization is preferred, you must set the parameterallow_small_regto true, which by default is false.rashomonValues: true or falseDescription: Enables extraction of Rashomon set. Setting it to false allows extracting only the optimal tree, allowing a more flexible way of setting Rashomon bound. Note: obtaining the optimal objective value is currently not supported in Python API.Default: truerashomon_bound_multiplierValues: Decimal > 0Description: Used to set the Rashomon bound. Rashomon bound = (1 + rashomon_bound_multiplier) * optimal objective value. Mutually exclusive withrashomon_boundandrashomon_bound_adder.Default: 0.05Warning: The size of Rashomon set increasing exponentially w.r.t. this argument.More parametersRashomon-specific configsrashomon_boundValues: Decimal > 0Description: Used to set the Rashomon bound. Directly setting the Rashomon bound if it is known. Mutually exclusive withrashomon_bound_multiplierandrashomon_bound_adder.Default: 0Warning: The size of Rashomon set increasing exponentially w.r.t. this argument.rashomon_bound_adderValues: Decimal > 0Description: Used to set the Rashomon bound. Rashomon bound = rashomon_bound_adder + optimal objective value. Mutually exclusive withrashomon_boundandrashomon_bound_multiplier.Default: 0Warning: The size of Rashomon set increasing exponentially w.r.t. this argument.output_accuracy_model_setValues: true or falseDescription: Enables outputting the Rashomon set with accuracy metric in a file named bymodel_set-accuracy-with the suffix indicated inrashomon_model_set_suffix. Note that it is not required for Python API to obtain the accuracy Rashomon set.Default: falseoutput_covered_setsValues: an array of string in['f1', 'bacc', 'auc'].Description: Enables outputting the Rashomon set with given metric in a file named bymodel_set-[metric]-with the suffix indicated inrashomon_model_set_suffix.Default: []covered_sets_thresholdsValues: an array of Decimals.Description: Sets the extraction threshold of given metric.Default: []rashomon_model_set_suffixValues: string representing a suffix of a file.Description: Sets file suffix for outputted model sets.Special Cases: None. Disable outputting to files by setting above config correspondingly. With an empty value the program still attempts to produce a file without suffix.Default: Empty stringrashomon_ignore_trivial_extensionsValues: true or falseDescription: Enables ignoring trivial splits, or terminal splits that does not improve accuracy.Default: truerashomon_trieValues: string representing a path to a file.Description: The output model set will be converted to trie representation, and be written to this file.Special Case: When set to empty string, no trie will be stored.Default: Empty stringFlagbalanceValues: true or falseDescription: Enables overriding the sample importance by equalizing the importance of each present classDefault: falsecancellationValues: true or falseDescription: Enables propagate up the dependency graph of task cancellationsDefault: truelook_aheadValues: true or falseDescription: Enables the one-step look-ahead bound implemented via scopesDefault: truesimilar_supportValues: true or falseDescription: Enables the similar support bound implemented via the distance indexDefault: truefeature_exchangeValues: true or falseDescription: Enables pruning of pairs of features using subset comparisonDefault: falsecontinuous_feature_exchangeValues: true or falseDescription: Enables pruning of pairs continuous of feature thresholds using subset comparisonDefault: falsefeature_transformValues: true or falseDescription: Enables the equivalence discovery through simple feature transformationsDefault: truerule_listValues: true or falseDescription: Enables rule-list constraints on modelsDefault: falsenon_binaryValues: true or falseDescription: Enables non-binary encodingDefault: falsediagnosticsValues: true or falseDescription: Enables printing of diagnostic trace when an error is encountered to standard outputDefault: falseverboseValues: true or falseDescription: Enables printing of configuration, progress, and results to standard outputDefault: falseTunersuncertainty_toleranceValues: Decimal within range [0,1]Description: Used to allow early termination of the algorithm. Any models produced as a result are guaranteed to score within the lowerbound and upperbound at the time of termination. However, the algorithm does not guarantee that the optimal model is within the produced model unless the uncertainty value has reached 0.Default: 0.0upperboundValues: Decimal within range [0,1]Description: Used to limit the risk of model search space. This can be used to ensure that no models are produced if even the optimal model exceeds a desired maximum risk. This also accelerates learning if the upperbound is taken from the risk of a nearly optimal model.Special Cases: When set to 0, the bound is not activated.Default: 0.0Limitsdepth_budgetValues: Integers >= 1Description: Used to set the maximum tree depth for solutions, counting a tree with just the root node as depth 1. 0 means unlimited.Default: 0time_limitValues: Decimal greater than or equal to 0Description: A time limit upon which the algorithm will terminate. If the time limit is reached, the algorithm will terminate with an error.Special Cases: When set to 0, no time limit is imposed.Default: 0precision_limitValues: Decimal greater than or equal to 0Description: The maximum number of significant figures considered when converting ordinal features into binary features.Special Cases: When set to 0, no limit is imposed.Default: 0stack_limitValues: Decimal greater than or equal to 0Description: The maximum number of bytes considered for use when allocating local buffers for worker threads.Special Cases: When set to 0, all local buffers will be allocated from the heap.Default: 0worker_limitValues: Decimal greater than or equal to 1Description: The maximum number of threads allocated to executing th algorithm.Special Cases: When set to 0, a single thread is created for each core detected on the machine.Default: 1FilescostsValues: string representing a path to a file.Description: This file must contain a CSV representing the cost matrix for calculating loss.The first row is a header listing every class that is present in the training dataEach subsequent row contains the cost incurred of predicitng classiwhen the true class isj, whereiis the row index andjis the column indexExample where each false negative costs 0.1 and each false positive costs 0.2 (and correct predictions costs 0.0):negative,positive
0.0,0.1
0.2,0.0Example for multi-class objectives:class-A,class-B,class-C
0.0,0.1,0.3
0.2,0.0,0.1
0.8,0.3,0.0Note: costs values are not normalized, so high cost values lower the relative weight of regularizationSpecial Case: When set to empty string, a default cost matrix is used which represents unweighted training misclassification.Default: Empty stringmodelValues: string representing a path to a file.Description: The output models will be written to this file.Special Case: When set to empty string, no model will be stored.Default: Empty stringprofileValues: string representing a path to a file.Description: Various analytics will be logged to this file.Special Case: When set to empty string, no analytics will be stored.Default: Empty stringtimingValues: string representing a path to a file.Description: The training time will be appended to this file.Special Case: When set to empty string, no training time will be stored.Default: Empty stringtraceValues: string representing a path to a directory.Description: snapshots used for trace visualization will be stored in this directorySpecial Case: When set to empty string, no snapshots are stored.Default: Empty stringtreeValues: string representing a path to a directory.Description: snapshots used for trace-tree visualization will be stored in this directorySpecial Case: When set to empty string, no snapshots are stored.Default: Empty stringExampleExample code to run TreeFARMS with threshold guessing, lower bound guessing, and depth limit. The example python file is available intreefarms/example.py. A tutorial ipython notebook is available intreefarms/tutorial.ipynb.StructureThis repository contains the following directories and files:.github: Configurations for GitHub action runners.doc: Documentationexperiments: Datasets and their configurations to run experimentstreefarms: Jupyter notebook, Python implementation and wrappers around C++ implementationinclude: Required 3rd-party header-only librarieslog: Log filessrc: Source files for C++ implementation and Python bindingtest: Source files for unit testsbuild.py: Python script that builds the project automaticallyCMakeLists.txt: Configuration file for the CMake build systempyproject.toml: Configuration file for the SciKit build systemsetup.py: Python script that builds the wheel fileFAQsIf you run into any issues when running TreeFARMS, consult theFAQsfirst.LicenseThis software is licensed under a 3-clause BSD license (see the LICENSE file for details).Related Work[1] Aglin, G.; Nijssen, S.; and Schaus, P. 2020. Learning optimal decision trees using caching branch-and-bound search. InAAAI Conference on Artificial Intelligence, volume 34, 3146–3153.[2] Angelino, E.; Larus-Stone, N.; Alabi, D.; Seltzer, M.; and Rudin, C. 2018. Learning Certifiably Optimal Rule Lists for Categorical Data.Journal of Machine Learning Research, 18(234): 1–78.[3] Breiman, L.; Friedman, J.; Stone, C. J.; and Olshen, R. A. 1984.Classification and Regression Trees. CRC press.[4] Hu, X.; Rudin, C.; and Seltzer, M. 2019. Optimal sparse decision trees. InAdvances in Neural Information Processing Systems, 7267–7275.[5] Lin, J.; Zhong, C.; Hu, D.; Rudin, C.; and Seltzer, M. 2020. Generalized and scalable optimal sparse decision trees. InInternational Conference on Machine Learning (ICML), 6150–6160.[6] Quinlan, J. R. 1993. C4.5:Programs for Machine Learning. Morgan Kaufmann[7] Verwer, S.; and Zhang, Y. 2019. Learning optimal classification trees using a binary linear program formulation. InAAAI
Conference on Artificial Intelligence, volume 33, 1625–1632.[8] Yang, H., Rudin, C., & Seltzer, M. (2017, July). Scalable Bayesian rule lists. InInternational Conference on Machine Learning (ICML)(pp. 3921-3930). PMLR.