Building Models
The Builder module of PyXAI allows you to build a tree-based classifier using nodes and leaves. This can be very useful to test and verify different types of explanations. All function definitions are available in the API. Some examples are provided in the Decision Tree, Random Forest and Boosted Tree pages.
PyXAI data structures are used directly in the Builder module.
-
DecisionNodeobject represents a node. LeafNodeis a leaf.- A
DecisionTreeobject consists ofDecisionNodeandLeafNode. - The models are specified through the objects
DecisionTreeRandomForestandBoostedTrees. - A
DecisionTreecontains only one tree whereas aRandomForestorBoostedTreesobject represents a set of trees and contains severalDecisionTreeobjects.
Each DecisionNode represents a condition “<id_feature> <operator> <threshold> ?” (such as “$x_4 \ge 0.5$ ?”) which can be created using the DecisionNode class:
When the operator and threshold parameters are not defined, they take their default values. In this case, the associated condition is of the form “$x \ge 0.5$ ?” which can be used to represent a binary feature (i.e. a feature with value 0 or 1).
The
DecisionTree,RandomForestandBoostedTreesmethods allow you to create models. During this process, binary variables representing the conditions (of the form “<id_feature> <operator> <threshold> ?”) of nodes are defined. These binary variables allow one to represent instances and explanations. The value of a binary variable denotes the condition used and its sign indicates whether this condition is satisfied or not in the model. By default, these binary variables have random values depending on the order according to which the tree is traversed. However, in rare cases when the features represent conditions (this is not true with most datasets), setting theforce_features_equal_to_binariesparameter toTrueallows us to get binary variables, and then explanations, that directly match the features, without needing to use theto_featuresmethod.
The Builder module of PyXAI also allows you to build a regression model with tree components using nodes and leaves. This can be very useful to test and verify different types of explanations.
An example of how to build a regression model is given in the second part of the Boosted Tree page.