Overview
The group importance module provides utility functions to compute and visualize the importances of groups of features or terms in a fitted Explainable Boosting Machine (EBM), enabling analysis of how sets of related features collectively contribute to model predictions.
Description
This research module extends EBM explanation capabilities by allowing users to group terms together and measure their joint importance:
- compute_group_importance: Computes the importance of a group of terms by summing their per-sample contributions and averaging the absolute values across all samples. For multiclass models, contributions are averaged across classes before aggregation.
- append_group_importance: Computes a group's importance and appends it to an existing (or new) global explanation object. The group importance appears in the Summary bar chart alongside individual term importances.
- get_group_and_individual_importances: Returns a sorted dictionary containing both individual term importances and group importances for specified term groups. Results are sorted in descending order.
- get_individual_importances: Returns a sorted dictionary of all individual EBM term importances.
- get_importance_per_top_groups: Creates incrementally larger groups starting from the most important individual term and expanding. Returns a pandas DataFrame showing how group importance grows as more terms are included.
- plot_importance_per_top_groups: Produces a Plotly line chart of the incremental group importance analysis.
Terms can be specified by name (string) or by index (integer). A "term" in this context covers both individual features and interaction pairs.
Usage
Use these functions when you want to understand how groups of related features (e.g., all demographic features, all lab test features) collectively contribute to an EBM's predictions. This is particularly useful for domain-specific feature grouping analysis or for understanding the marginal contribution of adding features to a group.
Code Reference
Source Location
- Repository: Interpretml_Interpret
- File:
python/interpret-core/interpret/glassbox/_ebm/_research/_group_importance.py
Signature
def compute_group_importance(term_list, ebm, X, contributions=None):
def append_group_importance(
term_list, ebm, X, group_name=None, global_exp=None,
global_exp_name=None, contributions=None,
):
def get_group_and_individual_importances(
term_groups_list, ebm, X, contributions=None,
):
def get_individual_importances(ebm, X, contributions=None):
def get_importance_per_top_groups(ebm, X):
def plot_importance_per_top_groups(ebm, X):
Import
from interpret.glassbox._ebm._research._group_importance import (
compute_group_importance,
append_group_importance,
get_group_and_individual_importances,
get_individual_importances,
get_importance_per_top_groups,
plot_importance_per_top_groups,
)
I/O Contract
compute_group_importance
| Name |
Type |
Required |
Description
|
| term_list |
list of str or int |
Yes |
List of term names or indices to group together
|
| ebm |
fitted EBM |
Yes |
A fitted Explainable Boosting Machine
|
| X |
numpy array |
Yes |
Samples used to compute group importance
|
| contributions |
numpy array |
No |
Precomputed contributions from ebm.eval_terms(X)
|
| Name |
Type |
Description
|
| importance |
float |
The group's importance (average of absolute summed contributions per sample)
|
append_group_importance
| Name |
Type |
Required |
Description
|
| term_list |
list of str or int |
Yes |
List of term names or indices
|
| ebm |
fitted EBM |
Yes |
A fitted EBM
|
| X |
numpy array |
Yes |
Samples for computing group importance
|
| group_name |
str |
No |
Custom name for the group (auto-generated from term names if omitted)
|
| global_exp |
EBMExplanation |
No |
Existing global explanation to append to (creates new one if omitted)
|
| global_exp_name |
str |
No |
Name for new global explanation if global_exp is None
|
| contributions |
numpy array |
No |
Precomputed contributions
|
| Name |
Type |
Description
|
| global_explanation |
EBMExplanation |
Global explanation with the group importance appended
|
get_importance_per_top_groups
| Name |
Type |
Required |
Description
|
| ebm |
fitted EBM |
Yes |
A fitted EBM
|
| X |
numpy array |
Yes |
Samples for computing group importance
|
| Name |
Type |
Description
|
| df |
pandas DataFrame |
DataFrame with columns: groups, terms_per_group, importances
|
Usage Examples
Compute Group Importance
from interpret.glassbox import ExplainableBoostingClassifier
from interpret.glassbox._ebm._research._group_importance import (
compute_group_importance,
append_group_importance,
)
ebm = ExplainableBoostingClassifier()
ebm.fit(X_train, y_train)
# Compute importance of a group of features
group_imp = compute_group_importance(
["Age", "MaritalStatus"], ebm, X_train
)
print(f"Group importance: {group_imp}")
# Append group importance to global explanation
global_exp = append_group_importance(
["Age", "MaritalStatus"], ebm, X_train,
group_name="Demographics"
)
global_exp.visualize(key=None)
Incremental Top-K Group Analysis
from interpret.glassbox._ebm._research._group_importance import (
get_importance_per_top_groups,
plot_importance_per_top_groups,
)
df = get_importance_per_top_groups(ebm, X_train)
print(df)
plot_importance_per_top_groups(ebm, X_train)
Related Pages