wildboar.explain.counterfactual._sf#

Module Contents#

Classes#

PredictionPaths

ShapeletForestCounterfactual

Counterfactual explanations for shapelet forest classifiers

Attributes#

wildboar.explain.counterfactual._sf.MIN_MATCHING_DISTANCE = 0.0001#
wildboar.explain.counterfactual._sf.euclidean_distance#
class wildboar.explain.counterfactual._sf.PredictionPaths(classes)#
__contains__(item)#
__getitem__(item)#
class wildboar.explain.counterfactual._sf.ShapeletForestCounterfactual(*, epsilon=1.0, batch_size=1, random_state=10)#

Bases: wildboar.explain.counterfactual.base.BaseCounterfactual

Counterfactual explanations for shapelet forest classifiers

paths_#

A dictionary of prediction paths per label

Type:

dict

Notes

This implementation only supports the reversible algorithm described by Karlsson (2020)

Warning

Only shapelet forests fit with the Euclidean distance is supported i.e., metric="euclidean"

References

Karlsson, I., Rebane, J., Papapetrou, P., & Gionis, A. (2020).

Locally and globally explainable time series tweaking. Knowledge and Information Systems, 62(5), 1671-1700.

Karlsson, I., Rebane, J., Papapetrou, P., & Gionis, A. (2018).

Explainable time series tweaking via irreversible and reversible temporal transformations. In 2018 IEEE International Conference on Data Mining (ICDM)

fit(estimator)#

Fit the counterfactual to a given estimator

Parameters:

estimator (object) – An estimator for which counterfactual explanations are produced

Return type:

self

transform(x, y)#

Transform the i:th sample in x to a sample that would be labeled as the i:th label in y

Parameters:
  • x (array-like of shape (n_samples, n_timestep) or (n_samples, n_dimension, n_timestep)) – The samples to generate counterfactual explanations for

  • y (array-like of shape (n_samples,)) – The desired label of the counterfactual sample

Returns:

  • counterfactuals (ndarray of same shape as x) – The counterfactual for each sample. If success[i] == False, then the value of counterfactuals[i] is undefined.

  • success (ndarray of shape (n_samples,)) – Boolean vector indicating successful transformations.

candidates(x, y)#