Tree¶
Tree¶
Tree
dataclass
¶
Tree(root: AbstractNode)
plot ¶
plot(
dataspec: DataSpecification,
max_depth: Optional[int],
label_classes: Optional[Sequence[str]],
options: Optional[PlotOptions] = None,
d3js_url: str = "https://d3js.org/d3.v6.min.js",
) -> TreePlot
Plots a decision tree.
Parameters:
-
dataspec(DataSpecification) –Dataspec of the tree.
-
max_depth(Optional[int]) –Maximum tree depth of the plot. Set to None for full depth.
-
label_classes(Optional[Sequence[str]]) –For classification, label classes of the dataset.
-
options(Optional[PlotOptions], default:None) –Advanced options for plotting. Set to None for default style.
-
d3js_url(str, default:'https://d3js.org/d3.v6.min.js') –URL to load the d3.js library from.
Returns:
-
TreePlot–The html content displaying the tree.
pretty ¶
Conditions¶
AbstractCondition
dataclass
¶
Generic condition.
Attrs
missing: Result of the evaluation of the condition if the input feature is missing. score: Score of a condition. The semantic depends on the learning algorithm.
NumericalHigherThanCondition
dataclass
¶
Bases: AbstractCondition
Condition of the form "attribute >= threshold".
Attrs
attribute: Attribute tested by the condition. threshold: Threshold.
CategoricalIsInCondition
dataclass
¶
Bases: AbstractCondition
Condition of the form "attribute in mask".
Attrs
attribute: Attribute tested by the condition. mask: Sorted mask values.
CategoricalSetContainsCondition
dataclass
¶
CategoricalSetContainsCondition(
missing: bool,
score: float,
attribute: int,
mask: Sequence[int],
)
Bases: AbstractCondition
Condition of the form "attribute intersect mask != empty".
Attrs
attribute: Attribute tested by the condition. mask: Sorted mask values.
DiscretizedNumericalHigherThanCondition
dataclass
¶
DiscretizedNumericalHigherThanCondition(
missing: bool,
score: float,
attribute: int,
threshold_idx: int,
)
Bases: AbstractCondition
Condition of the form "attribute >= bounds[threshold]".
Attrs
attribute: Attribute tested by the condition. threshold_idx: Index of threshold in dataspec.
IsMissingInCondition
dataclass
¶
Bases: AbstractCondition
Condition of the form "attribute is missing".
Attrs
attribute: Attribute (or one of the attributes) tested by the condition.
IsTrueCondition
dataclass
¶
Bases: AbstractCondition
Condition of the form "attribute is true".
Attrs
attribute: Attribute tested by the condition.
NumericalSparseObliqueCondition
dataclass
¶
NumericalSparseObliqueCondition(
missing: bool,
score: float,
attributes: Sequence[int],
weights: Sequence[float],
threshold: float,
na_replacements: Sequence[float],
)
Bases: AbstractCondition
Condition of the form "attributes * weights >= threshold".
Attrs
attributes: Attribute tested by the condition. weights: Weights for each of the attributes. threshold: Threshold value of the condition.
NumericalVectorSequenceCloserThanCondition
dataclass
¶
NumericalVectorSequenceCloserThanCondition(
missing: bool,
score: float,
attribute: int,
anchor: Sequence[float],
threshold2: float,
)
Bases: AbstractCondition
Condition of the type: exits a in Obs; |a - anchor|^2 <= threshold2.
Attrs
attribute: Numerical vector sequence attribute. anchor: Anchor to compare to. threshold2: Threshold value of the condition.
NumericalVectorSequenceProjectedMoreThanCondition
dataclass
¶
NumericalVectorSequenceProjectedMoreThanCondition(
missing: bool,
score: float,
attribute: int,
anchor: Sequence[float],
threshold: float,
)
Bases: AbstractCondition
Condition of the type: exits a in Obs; threshold.
Attrs
attribute: Numerical vector sequence attribute. anchor: Anchor to compare to. threshold: Threshold value of the condition.
Nodes¶
AbstractNode ¶
Leaf
dataclass
¶
Leaf(value: AbstractValue)
Bases: AbstractNode
pretty ¶
pretty(
dataspec: DataSpecification,
prefix: str,
is_pos: Optional[bool],
depth: int,
max_depth: Optional[int],
) -> str
NonLeaf
dataclass
¶
NonLeaf(
value: Optional[AbstractValue] = None,
condition: Optional[AbstractCondition] = None,
pos_child: Optional[AbstractNode] = None,
neg_child: Optional[AbstractNode] = None,
)
Bases: AbstractNode
pretty ¶
pretty(
dataspec: DataSpecification,
prefix: str,
is_pos: Optional[bool],
depth: int,
max_depth: Optional[int],
) -> str
Values¶
AbstractValue
dataclass
¶
RegressionValue
dataclass
¶
Bases: AbstractValue
The regression value of a regressive tree.
Can also be used in gradient-boosted-trees for classification and ranking.
Attrs
value: Value of the tree. The semantic depends on the tree: For Regression Random Forest and Regression GBDT, this value is a regressive value in the same unit as the label. For classification and ranking GBDTs, this value is a logit. standard_deviation: Optional standard deviation attached to the value.
ProbabilityValue
dataclass
¶
Bases: AbstractValue
A probability distribution value.
Used for random Forest / CART classification trees.
Attrs
probability: An array of probabilities of the label classes i.e. the i-th value is the probability of the "label_value_idx_to_value(..., i)" class. Note that the first value is reserved for the Out-of-vocabulary
UpliftValue
dataclass
¶
Bases: AbstractValue
The uplift value of a classification or regression uplift tree.
Attrs
treatment_effect: An array of the effects on the treatment groups. The i-th element of this array is the effect of the "i+1"th treatment compared to the control group.
AnomalyDetectionValue
dataclass
¶
Bases: AbstractValue
The value of an anomaly detection tree.
Attrs
num_examples_without_weight: Number of examples reaching this node.
Plotting¶
PlotOptions
dataclass
¶
PlotOptions(
margin: Optional[int] = 10,
node_x_size: Optional[int] = 160,
node_y_size: Optional[int] = 12 * 2 + 4,
node_x_offset: Optional[int] = 160 + 20,
node_y_offset: Optional[int] = 12 * 2 + 4 + 5,
font_size: Optional[int] = 10,
edge_rounding: Optional[int] = 20,
node_padding: Optional[int] = 2,
show_plot_bounding_box: Optional[bool] = False,
)
Options for plotting trees.
All the values are expressed in pixel.