treemind.Explainer
- class treemind.Explainer(model)
Extracts interpretable structure from tree models, showing how features and feature combinations influence predictions.
- Parameters:
model (Any)
- explain(degree, *, back_data=None)
Compute interaction metrics for feature groups of a specified degree.
- Parameters:
degree (int) – Interaction order: 1 for main effects, 2 for pairs, etc.
back_data (array-like, optional) – Optional dataset used to re-weight statistics for baseline-specific explanations.
- Returns:
A mapping from feature index tuples to per-class DataFrames.
- Return type:
- count_node(degree=2)
Count how often feature groups appear in tree split rules.
- Parameters:
degree (int, default=2) – Number of features in each group to count.
- Returns:
A DataFrame listing feature groups of the given degree and how often they appear in tree split rules, sorted by descending count.
- Return type:
pandas.DataFrame
- class treemind.Result
Container holding feature–interaction statistics produced by
Explainer.explain(). Acts like a mapping from feature-index tuples to per-classpandas.DataFrameobjects with computed metrics.The
__getitem__method simplifies this by returning a single DataFrame merged across classes, with a"class"column when applicable.Notes
The content of
Resultis intended to be read-only.- property data: Dict[Tuple[int, ...], Dict[int, DataFrame]]
Internal dictionary mapping feature-index tuples to per-class DataFrames.
- Returns:
The full internal representation of interaction data.
- Return type:
dict
- importance(combine_classes=False)
Calculate the mean absolute contribution metric (
I_abs) for each feature or interaction.The importance score for a group is:
\[I_{\text{abs}} = \frac{\sum_i \left| E[F\mid i]-\mu \right| \cdot \text{count}_i}{\sum_i \text{count}_i}\]- Parameters:
combine_classes (bool, default=False) – If True, aggregates per-class
I_absinto a single weighted value per group. If False, returns a row per class.- Returns:
A DataFrame listing feature or interaction importances (
I_abs), sorted by descending importance.- Return type:
pandas.DataFrame