Instance Based
CF(mlmodel, mode)
Bases: InstanceBase
Abstract class to implement Coutnterfactual Methods for time series data
Initialization of CF. Arguments: mlmodel [torch.nn.Module, Callabale, tf.keras.Model]: Machine Learning Model to be explained. mode str : Second dimension is feature --> 'feat', is time --> 'time'
explain()
Explains instance or model.
plot(original, org_label, exp, exp_label, vis_change=True, all_in_one=False, save_fig=None, figsize=(6.4, 4.8))
Basic Plot Function for visualizing Coutnerfactuals.
Arguments:
original np.array: Instance to be explained. Shape: mode = time
-> (time, feat)
or mode = time
-> (feat, time)
org_label int: Label of instance to be explained.
exp np.array: Explanation. mode = time
-> (time, feat)
or mode = time
-> (feat, time)
exp_label int: Label of Explanation.
vis_change bool: Change to be visualized as heatmap.
all_in_one bool: Original and Counterfactual in one plot.
save_fig str: Path to save fig at.
plot_in_one(item, org_label, exp, cf_label, save_fig=None, figsize=(6.4, 4.8))
Plot Function for Counterfactuals in uni-and multivariate setting. In the multivariate setting only the changed features are visualized.
Arguments:
item np.array: original instance. Shape: mode = time
-> (time, feat)
or mode = time
-> (feat, time)
org_label int: originally predicted label.
exp np.array: returned explanation. Shape: mode = time
-> (time, feat)
or mode = time
-> (feat, time)
cf_label int: lebel of returned instance.
figsize Tuple: Size of Figure (x,y).
save_fig str: Path to Save the figure.
plot_multi(item, org_label, exp, cf_label, figsize=(6.4, 4.8), save_fig=None)
Plot Function for Ates et al., used if multiple features are changed in a Multivariate Setting.
Also called via plot_in_one. Preferably, do not use directly.
Arguments:
item np.array: original instance. Shape: mode = time
-> (time, feat)
or mode = time
-> (feat, time)
org_label int: originally predicted label.
exp np.array: returned explanation. Shape: mode = time
-> (time, feat)
or mode = time
-> (feat, time)
cf_label int: lebel of returned instance.
figsize Tuple: Size of Figure (x,y).
save_fig str: Path to Save the figure.