shapiq.explainer.ThresholdNNExplainer¶
- class shapiq.explainer.ThresholdNNExplainer(model, class_index=None, data=None, index='SV', max_order=1)[source]¶
Bases:
NNExplainerBaseExplainer for threshold nearest neighbor models.
Implements the algorithm for efficiently computing exact Shapley values for threshold nearest neighbor models proposed by Wang et al.[1]. The algorithm has a runtime complexity of \(O(N)\) (when explaining a single data point), where \(N\) is the number of training samples.
References
Initializes the class.
- Parameters:
model (
RadiusNeighborsClassifier) – The NN model to explain. Must be an instance ofsklearn.neighbors.KNeighborsClassifierorsklearn.neighbors.RadiusNeighborsClassifier. The model must not use multi-output classification, i.e. theyvalue provided tomodel.fit(X, y)must be a 1D vector.class_index (
int|None) – The class index of the model to explain. Note that, as opposed to most Explainers, this must not beNone!data (np.ndarray | None)
index (ValidNNExplainerIndices)
max_order (int)
- Raises:
sklearn.exceptions.NotFittedError – The constructor was called with a model that hasn’t been fitted.
- explain_function(x)[source]¶
Explain a single prediction in terms of interaction values.
- Parameters:
- Return type:
- Returns:
The interaction values of the prediction.
- model: RadiusNeighborsClassifier¶
The model to be explained, either as a Model instance or a callable function.