NUNCF
Implementation after Delaney et al . https://github.com/e-delaney/Instance-Based_CFE_TSC
NativeGuideCF(model, data, backend='PYT', mode='feat', method='NUN_CF', distance_measure='dtw', n_neighbors=1, max_iter=500)
Bases: CF
NUN_CF according to [1] for both torch and tensorflow.
References
[1] Delaney, E., Greene, D., Keane, M.T.: Instance-Based Counterfactual Explanations for Time Series Classification. In: Sanchez-Ruiz, A.A., Floyd, M.W. (eds.) Case- Based Reasoning Research and Development, vol. 12877, pp. 32–47. Springer International Publishing, Cham (2021), series Title: Lecture Notes in Computer Science.
In this case differentiation between time & feat not necessary as implicitly given by CNN. Only works for CNNs due to the attribution methods.
Arguments:
model [torch.nn.Module, Callable, tf.keras.model]: classification model to explain
data Tuple: reference set as tuple (x,y)
backend str: 'PYT' or 'TF'
mode str: model either 'time' or 'feat'. time
-> (-1, time, feature)
or feat
-> (-1, feature, time)
method str: 'Nun_CF', 'dtw_bary_center' or 'native_guide'.
distance_measure str: sklearn appreviation for distance of knn.
n_neighbore int: # neighbors to select from.
max_iter int : max number of runs
explain(x, y)
' Explains a specific instance x. Arguments: x np.array : instance to be explained. y int: predicted label for instance x. Returns: Tuple: (counterfactual, counterfactual label)