General classification and regression explanations

For examples and interpretation, see my notebooks on general classification explanations and general regression explanations.

gshap.probability_distance.ProbabilityDistance

class gshap.probability_distance.ProbabilityDistance(positive, negative=None) [source]

This class measures how likely each predicted target value (output) was to have been generated by a 'positive' distribution or density, rather than a 'negative' distribution or density.

Parameters: positive : callable or list of callables

Densities and distributions take the output of a model, usually a (# observations,) or (# observations, # classes) vector. It returns a (# observations,) vector of probabilities that the predicted target value was generated by the density or distribution.

negative : callable or list of callables or None, default=None

Similarly defined. If None, the probability that each observation comes from a negative density or distribution will be treated as the complement of positive.

Attributes: positive : callable or list of callables

Set from the positive parameter.

negative : callable or list of callables

Set from the negative parameter.

Examples

import gshap
from gshap.probability_distance import ProbabilityDistance

from sklearn.datasets import load_iris
from sklearn.svm import SVC

X, y = load_iris(return_X_y=True)
clf = SVC(probability=True).fit(X,y)

# probability that each observation is in class 1
pos_distribution = lambda y_pred: y_pred[:,1]
# probability that each observation is in class 0
neg_distribution = lambda y_pred: y_pred[:,0]
g = ProbabilityDistance(pos_distribution, neg_distribution)
explainer = gshap.KernelExplainer(clf.predict_proba, X, g)
explainer.gshap_values(x, nsamples=1000)

Out:

array([0.02175944, 0.01505252, 0.17106646, 0.13605429])

Methods

__call__(self, output) [source]

Parameters: output : np.array

Model output, usually (# observations,) or (# obervations, # classes) array for regression or classification problems, respectively.

Returns: probability : float

Probability that every predicted target value was generated by a positive density or distribution, rather than a negative density or distribution.