GLANCE¶
Group-Level Anchor-based Counterfactual Explanations
GLANCE uses anchors to define groups and generate group-level counterfactuals.
Overview¶
GLANCE identifies anchor points that define natural groupings and generates counterfactuals applicable to each group.
Usage¶
from counterfactuals.cf_methods.group_methods import GLANCE
method = GLANCE(
gen_model=gen_model,
disc_model=classifier,
disc_model_criterion=criterion,
device="cuda"
)
result = method.explain(
X=X_test,
y_origin=y_test,
y_target=target_class,
X_train=X_train,
y_train=y_train
)
API Reference¶
GLANCE
¶
Source code in counterfactuals/cf_methods/group_methods/glance/glance.py
__merge_clusters
¶
Merge two clusters by averaging their centroids, updating the labels and merging the actions
Source code in counterfactuals/cf_methods/group_methods/glance/glance.py
get_clusters
¶
Returns the final clusters as a list of tuples
Each tuple contains: - The centroid of the cluster - The label of the cluster - The average action of the cluster (centroid + action = counterfactual)