wildboar.explain.counterfactual._nn#

Module Contents#

Classes#

KNeighborsCounterfactual

Fit a counterfactual explainer to a k-nearest neighbors classifier

class wildboar.explain.counterfactual._nn.KNeighborsCounterfactual(random_state=None)#

Bases: wildboar.explain.counterfactual.base.BaseCounterfactual

Fit a counterfactual explainer to a k-nearest neighbors classifier

explainer_#

The explainer for each label

Type:

dict

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.

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.