PivotTreeStump#

class PivotTreeStump[source]#

Bases: object

Mixin of the pivot stumps (PivotTreeStumpClassifier and PivotTreeStumpRegressor): the PivotTransformer built from the parameters of the stump, the pivots of the split and its rule.

The subclass defines the parameters and the splitter, by deriving also from the decision tree stump of its task (class PivotTreeStumpClassifier(PivotTreeStump, DecisionTreeStumpClassifier)).

property X_split_instance#

The pivot of the split, standardized (categorical features one-hot encoded); None if not fitted.

get_pivots()[source]#

Pivots of the node, as indices of instances of the training set.

Returns:

pivots – descriptives (medoids), discriminatives and candidates (both) pivots of the node, and the pivot used by the split.

Return type:

dict

Examples

>>> from sklearn.datasets import load_iris
>>> from RuleTree.stumps.classification import PivotTreeStumpClassifier
>>> X, y = load_iris(return_X_y=True)
>>> pivots = PivotTreeStumpClassifier(random_state=0)
>>> pivots = pivots.fit(X, y, context=None, node_id=None, cache=None).get_pivots()
>>> pivots["descriptives"], pivots["discriminatives"], pivots["used"]
([7, 99, 147], [27, 76, 108], 76)
get_rule(columns_names=None, scaler=None, float_precision=3)[source]#

Rule of the split, P_<i> <= threshold, where P_<i> is the distance from the training instance i.

Parameters:
  • columns_names (list of str, default=None) – Not used: the rule does not name the features.

  • scaler (TransformerMixin, default=None) – Not used: the distances are computed on the data standardized by the stump.

  • float_precision (int, default=3) – Number of decimals of the threshold; None for no rounding.

Returns:

rule – feature_idx (the pivot), threshold, is_categorical, feature_name, the condition of the left child (textual_rule, blob_rule) and its negation (not_textual_rule, not_blob_rule). Empty if the stump is not fitted.

Return type:

dict

get_plot_rule(columns_names=None, scaler=None, float_precision=3)[source]#

What the node of the split shows in RuleTree.plot_tree: the rule, and the pivot as given to fit (time series, images and texts), drawn below it with show_media.

Parameters:
  • columns_names (list of str, default=None) – Not used.

  • scaler (TransformerMixin, default=None) – Not used.

  • float_precision (int, default=3) – Number of decimals of the threshold.

Returns:

rule – label, and media_values with the pivot (see pivot_media()).

Return type:

dict