repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
apache/incubator-mxnet
python/mxnet/contrib/onnx/mx2onnx/export_onnx.py
MXNetGraph.get_outputs
def get_outputs(sym, params, in_shape, in_label): """ Infer output shapes and return dictionary of output name to shape :param :class:`~mxnet.symbol.Symbol` sym: symbol to perform infer shape on :param dic of (str, nd.NDArray) params: :param list of tuple(int, ...) in_shape: list of all...
python
def get_outputs(sym, params, in_shape, in_label): """ Infer output shapes and return dictionary of output name to shape :param :class:`~mxnet.symbol.Symbol` sym: symbol to perform infer shape on :param dic of (str, nd.NDArray) params: :param list of tuple(int, ...) in_shape: list of all...
[ "def", "get_outputs", "(", "sym", ",", "params", ",", "in_shape", ",", "in_label", ")", ":", "# remove any input listed in params from sym.list_inputs() and bind them to the input shapes provided", "# by user. Also remove in_label, which is the name of the label symbol that may have been u...
Infer output shapes and return dictionary of output name to shape :param :class:`~mxnet.symbol.Symbol` sym: symbol to perform infer shape on :param dic of (str, nd.NDArray) params: :param list of tuple(int, ...) in_shape: list of all input shapes :param in_label: name of label typicall...
[ "Infer", "output", "shapes", "and", "return", "dictionary", "of", "output", "name", "to", "shape" ]
1af29e9c060a4c7d60eeaacba32afdb9a7775ba7
https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/mx2onnx/export_onnx.py#L123-L156
train
apache/incubator-mxnet
python/mxnet/contrib/onnx/mx2onnx/export_onnx.py
MXNetGraph.convert_weights_to_numpy
def convert_weights_to_numpy(weights_dict): """Convert weights to numpy""" return dict([(k.replace("arg:", "").replace("aux:", ""), v.asnumpy()) for k, v in weights_dict.items()])
python
def convert_weights_to_numpy(weights_dict): """Convert weights to numpy""" return dict([(k.replace("arg:", "").replace("aux:", ""), v.asnumpy()) for k, v in weights_dict.items()])
[ "def", "convert_weights_to_numpy", "(", "weights_dict", ")", ":", "return", "dict", "(", "[", "(", "k", ".", "replace", "(", "\"arg:\"", ",", "\"\"", ")", ".", "replace", "(", "\"aux:\"", ",", "\"\"", ")", ",", "v", ".", "asnumpy", "(", ")", ")", "fo...
Convert weights to numpy
[ "Convert", "weights", "to", "numpy" ]
1af29e9c060a4c7d60eeaacba32afdb9a7775ba7
https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/mx2onnx/export_onnx.py#L159-L162
train
apache/incubator-mxnet
python/mxnet/contrib/onnx/mx2onnx/export_onnx.py
MXNetGraph.create_onnx_graph_proto
def create_onnx_graph_proto(self, sym, params, in_shape, in_type, verbose=False): """Convert MXNet graph to ONNX graph Parameters ---------- sym : :class:`~mxnet.symbol.Symbol` MXNet symbol object params : dict of ``str`` to :class:`~mxnet.ndarray.NDArray` ...
python
def create_onnx_graph_proto(self, sym, params, in_shape, in_type, verbose=False): """Convert MXNet graph to ONNX graph Parameters ---------- sym : :class:`~mxnet.symbol.Symbol` MXNet symbol object params : dict of ``str`` to :class:`~mxnet.ndarray.NDArray` ...
[ "def", "create_onnx_graph_proto", "(", "self", ",", "sym", ",", "params", ",", "in_shape", ",", "in_type", ",", "verbose", "=", "False", ")", ":", "try", ":", "from", "onnx", "import", "(", "checker", ",", "helper", ",", "NodeProto", ",", "ValueInfoProto",...
Convert MXNet graph to ONNX graph Parameters ---------- sym : :class:`~mxnet.symbol.Symbol` MXNet symbol object params : dict of ``str`` to :class:`~mxnet.ndarray.NDArray` Dict of converted parameters stored in ``mxnet.ndarray.NDArray`` format in_shape : ...
[ "Convert", "MXNet", "graph", "to", "ONNX", "graph" ]
1af29e9c060a4c7d60eeaacba32afdb9a7775ba7
https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/python/mxnet/contrib/onnx/mx2onnx/export_onnx.py#L164-L313
train
apache/incubator-mxnet
example/ssd/train/train_net.py
get_lr_scheduler
def get_lr_scheduler(learning_rate, lr_refactor_step, lr_refactor_ratio, num_example, batch_size, begin_epoch): """ Compute learning rate and refactor scheduler Parameters: --------- learning_rate : float original learning rate lr_refactor_step : comma separated str...
python
def get_lr_scheduler(learning_rate, lr_refactor_step, lr_refactor_ratio, num_example, batch_size, begin_epoch): """ Compute learning rate and refactor scheduler Parameters: --------- learning_rate : float original learning rate lr_refactor_step : comma separated str...
[ "def", "get_lr_scheduler", "(", "learning_rate", ",", "lr_refactor_step", ",", "lr_refactor_ratio", ",", "num_example", ",", "batch_size", ",", "begin_epoch", ")", ":", "assert", "lr_refactor_ratio", ">", "0", "iter_refactor", "=", "[", "int", "(", "r", ")", "fo...
Compute learning rate and refactor scheduler Parameters: --------- learning_rate : float original learning rate lr_refactor_step : comma separated str epochs to change learning rate lr_refactor_ratio : float lr *= ratio at certain steps num_example : int number o...
[ "Compute", "learning", "rate", "and", "refactor", "scheduler" ]
1af29e9c060a4c7d60eeaacba32afdb9a7775ba7
https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/train/train_net.py#L48-L88
train
apache/incubator-mxnet
example/ssd/train/train_net.py
train_net
def train_net(net, train_path, num_classes, batch_size, data_shape, mean_pixels, resume, finetune, pretrained, epoch, prefix, ctx, begin_epoch, end_epoch, frequent, learning_rate, momentum, weight_decay, lr_refactor_step, lr_refactor_ratio, freeze_layer_pattern=''...
python
def train_net(net, train_path, num_classes, batch_size, data_shape, mean_pixels, resume, finetune, pretrained, epoch, prefix, ctx, begin_epoch, end_epoch, frequent, learning_rate, momentum, weight_decay, lr_refactor_step, lr_refactor_ratio, freeze_layer_pattern=''...
[ "def", "train_net", "(", "net", ",", "train_path", ",", "num_classes", ",", "batch_size", ",", "data_shape", ",", "mean_pixels", ",", "resume", ",", "finetune", ",", "pretrained", ",", "epoch", ",", "prefix", ",", "ctx", ",", "begin_epoch", ",", "end_epoch",...
Wrapper for training phase. Parameters: ---------- net : str symbol name for the network structure train_path : str record file path for training num_classes : int number of object classes, not including background batch_size : int training batch-size data_sh...
[ "Wrapper", "for", "training", "phase", "." ]
1af29e9c060a4c7d60eeaacba32afdb9a7775ba7
https://github.com/apache/incubator-mxnet/blob/1af29e9c060a4c7d60eeaacba32afdb9a7775ba7/example/ssd/train/train_net.py#L90-L279
train
slundberg/shap
shap/datasets.py
imagenet50
def imagenet50(display=False, resolution=224): """ This is a set of 50 images representative of ImageNet images. This dataset was collected by randomly finding a working ImageNet link and then pasting the original ImageNet image into Google image search restricted to images licensed for reuse. A simila...
python
def imagenet50(display=False, resolution=224): """ This is a set of 50 images representative of ImageNet images. This dataset was collected by randomly finding a working ImageNet link and then pasting the original ImageNet image into Google image search restricted to images licensed for reuse. A simila...
[ "def", "imagenet50", "(", "display", "=", "False", ",", "resolution", "=", "224", ")", ":", "prefix", "=", "github_data_url", "+", "\"imagenet50_\"", "X", "=", "np", ".", "load", "(", "cache", "(", "prefix", "+", "\"%sx%s.npy\"", "%", "(", "resolution", ...
This is a set of 50 images representative of ImageNet images. This dataset was collected by randomly finding a working ImageNet link and then pasting the original ImageNet image into Google image search restricted to images licensed for reuse. A similar image (now with rights to reuse) was downloaded as a ...
[ "This", "is", "a", "set", "of", "50", "images", "representative", "of", "ImageNet", "images", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L13-L28
train
slundberg/shap
shap/datasets.py
boston
def boston(display=False): """ Return the boston housing data in a nice package. """ d = sklearn.datasets.load_boston() df = pd.DataFrame(data=d.data, columns=d.feature_names) # pylint: disable=E1101 return df, d.target
python
def boston(display=False): """ Return the boston housing data in a nice package. """ d = sklearn.datasets.load_boston() df = pd.DataFrame(data=d.data, columns=d.feature_names) # pylint: disable=E1101 return df, d.target
[ "def", "boston", "(", "display", "=", "False", ")", ":", "d", "=", "sklearn", ".", "datasets", ".", "load_boston", "(", ")", "df", "=", "pd", ".", "DataFrame", "(", "data", "=", "d", ".", "data", ",", "columns", "=", "d", ".", "feature_names", ")",...
Return the boston housing data in a nice package.
[ "Return", "the", "boston", "housing", "data", "in", "a", "nice", "package", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L30-L35
train
slundberg/shap
shap/datasets.py
imdb
def imdb(display=False): """ Return the clssic IMDB sentiment analysis training data in a nice package. Full data is at: http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz Paper to cite when using the data is: http://www.aclweb.org/anthology/P11-1015 """ with open(cache(github_data_url...
python
def imdb(display=False): """ Return the clssic IMDB sentiment analysis training data in a nice package. Full data is at: http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz Paper to cite when using the data is: http://www.aclweb.org/anthology/P11-1015 """ with open(cache(github_data_url...
[ "def", "imdb", "(", "display", "=", "False", ")", ":", "with", "open", "(", "cache", "(", "github_data_url", "+", "\"imdb_train.txt\"", ")", ")", "as", "f", ":", "data", "=", "f", ".", "readlines", "(", ")", "y", "=", "np", ".", "ones", "(", "25000...
Return the clssic IMDB sentiment analysis training data in a nice package. Full data is at: http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz Paper to cite when using the data is: http://www.aclweb.org/anthology/P11-1015
[ "Return", "the", "clssic", "IMDB", "sentiment", "analysis", "training", "data", "in", "a", "nice", "package", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L37-L48
train
slundberg/shap
shap/datasets.py
communitiesandcrime
def communitiesandcrime(display=False): """ Predict total number of non-violent crimes per 100K popuation. This dataset is from the classic UCI Machine Learning repository: https://archive.ics.uci.edu/ml/datasets/Communities+and+Crime+Unnormalized """ raw_data = pd.read_csv( cache(github_d...
python
def communitiesandcrime(display=False): """ Predict total number of non-violent crimes per 100K popuation. This dataset is from the classic UCI Machine Learning repository: https://archive.ics.uci.edu/ml/datasets/Communities+and+Crime+Unnormalized """ raw_data = pd.read_csv( cache(github_d...
[ "def", "communitiesandcrime", "(", "display", "=", "False", ")", ":", "raw_data", "=", "pd", ".", "read_csv", "(", "cache", "(", "github_data_url", "+", "\"CommViolPredUnnormalizedData.txt\"", ")", ",", "na_values", "=", "\"?\"", ")", "# find the indices where the t...
Predict total number of non-violent crimes per 100K popuation. This dataset is from the classic UCI Machine Learning repository: https://archive.ics.uci.edu/ml/datasets/Communities+and+Crime+Unnormalized
[ "Predict", "total", "number", "of", "non", "-", "violent", "crimes", "per", "100K", "popuation", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L50-L71
train
slundberg/shap
shap/datasets.py
diabetes
def diabetes(display=False): """ Return the diabetes data in a nice package. """ d = sklearn.datasets.load_diabetes() df = pd.DataFrame(data=d.data, columns=d.feature_names) # pylint: disable=E1101 return df, d.target
python
def diabetes(display=False): """ Return the diabetes data in a nice package. """ d = sklearn.datasets.load_diabetes() df = pd.DataFrame(data=d.data, columns=d.feature_names) # pylint: disable=E1101 return df, d.target
[ "def", "diabetes", "(", "display", "=", "False", ")", ":", "d", "=", "sklearn", ".", "datasets", ".", "load_diabetes", "(", ")", "df", "=", "pd", ".", "DataFrame", "(", "data", "=", "d", ".", "data", ",", "columns", "=", "d", ".", "feature_names", ...
Return the diabetes data in a nice package.
[ "Return", "the", "diabetes", "data", "in", "a", "nice", "package", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L73-L78
train
slundberg/shap
shap/datasets.py
iris
def iris(display=False): """ Return the classic iris data in a nice package. """ d = sklearn.datasets.load_iris() df = pd.DataFrame(data=d.data, columns=d.feature_names) # pylint: disable=E1101 if display: return df, [d.target_names[v] for v in d.target] # pylint: disable=E1101 else: ...
python
def iris(display=False): """ Return the classic iris data in a nice package. """ d = sklearn.datasets.load_iris() df = pd.DataFrame(data=d.data, columns=d.feature_names) # pylint: disable=E1101 if display: return df, [d.target_names[v] for v in d.target] # pylint: disable=E1101 else: ...
[ "def", "iris", "(", "display", "=", "False", ")", ":", "d", "=", "sklearn", ".", "datasets", ".", "load_iris", "(", ")", "df", "=", "pd", ".", "DataFrame", "(", "data", "=", "d", ".", "data", ",", "columns", "=", "d", ".", "feature_names", ")", "...
Return the classic iris data in a nice package.
[ "Return", "the", "classic", "iris", "data", "in", "a", "nice", "package", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L81-L89
train
slundberg/shap
shap/datasets.py
adult
def adult(display=False): """ Return the Adult census data in a nice package. """ dtypes = [ ("Age", "float32"), ("Workclass", "category"), ("fnlwgt", "float32"), ("Education", "category"), ("Education-Num", "float32"), ("Marital Status", "category"), ("Occupation", "category"), ("Relati...
python
def adult(display=False): """ Return the Adult census data in a nice package. """ dtypes = [ ("Age", "float32"), ("Workclass", "category"), ("fnlwgt", "float32"), ("Education", "category"), ("Education-Num", "float32"), ("Marital Status", "category"), ("Occupation", "category"), ("Relati...
[ "def", "adult", "(", "display", "=", "False", ")", ":", "dtypes", "=", "[", "(", "\"Age\"", ",", "\"float32\"", ")", ",", "(", "\"Workclass\"", ",", "\"category\"", ")", ",", "(", "\"fnlwgt\"", ",", "\"float32\"", ")", ",", "(", "\"Education\"", ",", "...
Return the Adult census data in a nice package.
[ "Return", "the", "Adult", "census", "data", "in", "a", "nice", "package", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L92-L128
train
slundberg/shap
shap/datasets.py
nhanesi
def nhanesi(display=False): """ A nicely packaged version of NHANES I data with surivival times as labels. """ X = pd.read_csv(cache(github_data_url + "NHANESI_subset_X.csv")) y = pd.read_csv(cache(github_data_url + "NHANESI_subset_y.csv"))["y"] if display: X_display = X.copy() X_dis...
python
def nhanesi(display=False): """ A nicely packaged version of NHANES I data with surivival times as labels. """ X = pd.read_csv(cache(github_data_url + "NHANESI_subset_X.csv")) y = pd.read_csv(cache(github_data_url + "NHANESI_subset_y.csv"))["y"] if display: X_display = X.copy() X_dis...
[ "def", "nhanesi", "(", "display", "=", "False", ")", ":", "X", "=", "pd", ".", "read_csv", "(", "cache", "(", "github_data_url", "+", "\"NHANESI_subset_X.csv\"", ")", ")", "y", "=", "pd", ".", "read_csv", "(", "cache", "(", "github_data_url", "+", "\"NHA...
A nicely packaged version of NHANES I data with surivival times as labels.
[ "A", "nicely", "packaged", "version", "of", "NHANES", "I", "data", "with", "surivival", "times", "as", "labels", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L131-L141
train
slundberg/shap
shap/datasets.py
cric
def cric(display=False): """ A nicely packaged version of CRIC data with progression to ESRD within 4 years as the label. """ X = pd.read_csv(cache(github_data_url + "CRIC_time_4yearESRD_X.csv")) y = np.loadtxt(cache(github_data_url + "CRIC_time_4yearESRD_y.csv")) if display: X_display = X.c...
python
def cric(display=False): """ A nicely packaged version of CRIC data with progression to ESRD within 4 years as the label. """ X = pd.read_csv(cache(github_data_url + "CRIC_time_4yearESRD_X.csv")) y = np.loadtxt(cache(github_data_url + "CRIC_time_4yearESRD_y.csv")) if display: X_display = X.c...
[ "def", "cric", "(", "display", "=", "False", ")", ":", "X", "=", "pd", ".", "read_csv", "(", "cache", "(", "github_data_url", "+", "\"CRIC_time_4yearESRD_X.csv\"", ")", ")", "y", "=", "np", ".", "loadtxt", "(", "cache", "(", "github_data_url", "+", "\"CR...
A nicely packaged version of CRIC data with progression to ESRD within 4 years as the label.
[ "A", "nicely", "packaged", "version", "of", "CRIC", "data", "with", "progression", "to", "ESRD", "within", "4", "years", "as", "the", "label", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L143-L152
train
slundberg/shap
shap/datasets.py
corrgroups60
def corrgroups60(display=False): """ Correlated Groups 60 A simulated dataset with tight correlations among distinct groups of features. """ # set a constant seed old_seed = np.random.seed() np.random.seed(0) # generate dataset with known correlation N = 1000 M = 60 # set...
python
def corrgroups60(display=False): """ Correlated Groups 60 A simulated dataset with tight correlations among distinct groups of features. """ # set a constant seed old_seed = np.random.seed() np.random.seed(0) # generate dataset with known correlation N = 1000 M = 60 # set...
[ "def", "corrgroups60", "(", "display", "=", "False", ")", ":", "# set a constant seed", "old_seed", "=", "np", ".", "random", ".", "seed", "(", ")", "np", ".", "random", ".", "seed", "(", "0", ")", "# generate dataset with known correlation", "N", "=", "1000...
Correlated Groups 60 A simulated dataset with tight correlations among distinct groups of features.
[ "Correlated", "Groups", "60", "A", "simulated", "dataset", "with", "tight", "correlations", "among", "distinct", "groups", "of", "features", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L155-L197
train
slundberg/shap
shap/datasets.py
independentlinear60
def independentlinear60(display=False): """ A simulated dataset with tight correlations among distinct groups of features. """ # set a constant seed old_seed = np.random.seed() np.random.seed(0) # generate dataset with known correlation N = 1000 M = 60 # set one coefficent from ea...
python
def independentlinear60(display=False): """ A simulated dataset with tight correlations among distinct groups of features. """ # set a constant seed old_seed = np.random.seed() np.random.seed(0) # generate dataset with known correlation N = 1000 M = 60 # set one coefficent from ea...
[ "def", "independentlinear60", "(", "display", "=", "False", ")", ":", "# set a constant seed", "old_seed", "=", "np", ".", "random", ".", "seed", "(", ")", "np", ".", "random", ".", "seed", "(", "0", ")", "# generate dataset with known correlation", "N", "=", ...
A simulated dataset with tight correlations among distinct groups of features.
[ "A", "simulated", "dataset", "with", "tight", "correlations", "among", "distinct", "groups", "of", "features", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L200-L225
train
slundberg/shap
shap/datasets.py
rank
def rank(): """ Ranking datasets from lightgbm repository. """ rank_data_url = 'https://raw.githubusercontent.com/Microsoft/LightGBM/master/examples/lambdarank/' x_train, y_train = sklearn.datasets.load_svmlight_file(cache(rank_data_url + 'rank.train')) x_test, y_test = sklearn.datasets.load_svmligh...
python
def rank(): """ Ranking datasets from lightgbm repository. """ rank_data_url = 'https://raw.githubusercontent.com/Microsoft/LightGBM/master/examples/lambdarank/' x_train, y_train = sklearn.datasets.load_svmlight_file(cache(rank_data_url + 'rank.train')) x_test, y_test = sklearn.datasets.load_svmligh...
[ "def", "rank", "(", ")", ":", "rank_data_url", "=", "'https://raw.githubusercontent.com/Microsoft/LightGBM/master/examples/lambdarank/'", "x_train", ",", "y_train", "=", "sklearn", ".", "datasets", ".", "load_svmlight_file", "(", "cache", "(", "rank_data_url", "+", "'rank...
Ranking datasets from lightgbm repository.
[ "Ranking", "datasets", "from", "lightgbm", "repository", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/datasets.py#L234-L242
train
slundberg/shap
shap/benchmark/measures.py
batch_remove_retrain
def batch_remove_retrain(nmask_train, nmask_test, X_train, y_train, X_test, y_test, attr_train, attr_test, model_generator, metric): """ An approximation of holdout that only retraines the model once. This is alse called ROAR (RemOve And Retrain) in work by Google. It is much more computationally efficient...
python
def batch_remove_retrain(nmask_train, nmask_test, X_train, y_train, X_test, y_test, attr_train, attr_test, model_generator, metric): """ An approximation of holdout that only retraines the model once. This is alse called ROAR (RemOve And Retrain) in work by Google. It is much more computationally efficient...
[ "def", "batch_remove_retrain", "(", "nmask_train", ",", "nmask_test", ",", "X_train", ",", "y_train", ",", "X_test", ",", "y_test", ",", "attr_train", ",", "attr_test", ",", "model_generator", ",", "metric", ")", ":", "warnings", ".", "warn", "(", "\"The retra...
An approximation of holdout that only retraines the model once. This is alse called ROAR (RemOve And Retrain) in work by Google. It is much more computationally efficient that the holdout method because it masks the most important features in every sample and then retrains the model once, instead of retrai...
[ "An", "approximation", "of", "holdout", "that", "only", "retraines", "the", "model", "once", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/measures.py#L158-L193
train
slundberg/shap
shap/benchmark/measures.py
keep_retrain
def keep_retrain(nkeep, X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model, random_state): """ The model is retrained for each test sample with the non-important features set to a constant. If you want to know how important a set of features is you can ask how the model would b...
python
def keep_retrain(nkeep, X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model, random_state): """ The model is retrained for each test sample with the non-important features set to a constant. If you want to know how important a set of features is you can ask how the model would b...
[ "def", "keep_retrain", "(", "nkeep", ",", "X_train", ",", "y_train", ",", "X_test", ",", "y_test", ",", "attr_test", ",", "model_generator", ",", "metric", ",", "trained_model", ",", "random_state", ")", ":", "warnings", ".", "warn", "(", "\"The retrain based ...
The model is retrained for each test sample with the non-important features set to a constant. If you want to know how important a set of features is you can ask how the model would be different if only those features had existed. To determine this we can mask the other features across the entire training ...
[ "The", "model", "is", "retrained", "for", "each", "test", "sample", "with", "the", "non", "-", "important", "features", "set", "to", "a", "constant", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/measures.py#L196-L258
train
slundberg/shap
shap/benchmark/measures.py
keep_mask
def keep_mask(nkeep, X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model, random_state): """ The model is revaluated for each test sample with the non-important features set to their mean. """ X_train, X_test = to_array(X_train, X_test) # how many features to mask a...
python
def keep_mask(nkeep, X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model, random_state): """ The model is revaluated for each test sample with the non-important features set to their mean. """ X_train, X_test = to_array(X_train, X_test) # how many features to mask a...
[ "def", "keep_mask", "(", "nkeep", ",", "X_train", ",", "y_train", ",", "X_test", ",", "y_test", ",", "attr_test", ",", "model_generator", ",", "metric", ",", "trained_model", ",", "random_state", ")", ":", "X_train", ",", "X_test", "=", "to_array", "(", "X...
The model is revaluated for each test sample with the non-important features set to their mean.
[ "The", "model", "is", "revaluated", "for", "each", "test", "sample", "with", "the", "non", "-", "important", "features", "set", "to", "their", "mean", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/measures.py#L260-L281
train
slundberg/shap
shap/benchmark/measures.py
keep_impute
def keep_impute(nkeep, X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model, random_state): """ The model is revaluated for each test sample with the non-important features set to an imputed value. Note that the imputation is done using a multivariate normality assumption on the ...
python
def keep_impute(nkeep, X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model, random_state): """ The model is revaluated for each test sample with the non-important features set to an imputed value. Note that the imputation is done using a multivariate normality assumption on the ...
[ "def", "keep_impute", "(", "nkeep", ",", "X_train", ",", "y_train", ",", "X_test", ",", "y_test", ",", "attr_test", ",", "model_generator", ",", "metric", ",", "trained_model", ",", "random_state", ")", ":", "X_train", ",", "X_test", "=", "to_array", "(", ...
The model is revaluated for each test sample with the non-important features set to an imputed value. Note that the imputation is done using a multivariate normality assumption on the dataset. This depends on being able to estimate the full data covariance matrix (and inverse) accuractly. So X_train.shape[0] s...
[ "The", "model", "is", "revaluated", "for", "each", "test", "sample", "with", "the", "non", "-", "important", "features", "set", "to", "an", "imputed", "value", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/measures.py#L283-L318
train
slundberg/shap
shap/benchmark/measures.py
keep_resample
def keep_resample(nkeep, X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model, random_state): """ The model is revaluated for each test sample with the non-important features set to resample background values. """ # why broken? overwriting? X_train, X_test = to_array(X_train,...
python
def keep_resample(nkeep, X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model, random_state): """ The model is revaluated for each test sample with the non-important features set to resample background values. """ # why broken? overwriting? X_train, X_test = to_array(X_train,...
[ "def", "keep_resample", "(", "nkeep", ",", "X_train", ",", "y_train", ",", "X_test", ",", "y_test", ",", "attr_test", ",", "model_generator", ",", "metric", ",", "trained_model", ",", "random_state", ")", ":", "# why broken? overwriting?", "X_train", ",", "X_tes...
The model is revaluated for each test sample with the non-important features set to resample background values.
[ "The", "model", "is", "revaluated", "for", "each", "test", "sample", "with", "the", "non", "-", "important", "features", "set", "to", "resample", "background", "values", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/measures.py#L320-L345
train
slundberg/shap
shap/benchmark/measures.py
local_accuracy
def local_accuracy(X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model): """ The how well do the features plus a constant base rate sum up to the model output. """ X_train, X_test = to_array(X_train, X_test) # how many features to mask assert X_train.shape[1] == X_t...
python
def local_accuracy(X_train, y_train, X_test, y_test, attr_test, model_generator, metric, trained_model): """ The how well do the features plus a constant base rate sum up to the model output. """ X_train, X_test = to_array(X_train, X_test) # how many features to mask assert X_train.shape[1] == X_t...
[ "def", "local_accuracy", "(", "X_train", ",", "y_train", ",", "X_test", ",", "y_test", ",", "attr_test", ",", "model_generator", ",", "metric", ",", "trained_model", ")", ":", "X_train", ",", "X_test", "=", "to_array", "(", "X_train", ",", "X_test", ")", "...
The how well do the features plus a constant base rate sum up to the model output.
[ "The", "how", "well", "do", "the", "features", "plus", "a", "constant", "base", "rate", "sum", "up", "to", "the", "model", "output", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/measures.py#L384-L396
train
slundberg/shap
shap/benchmark/measures.py
const_rand
def const_rand(size, seed=23980): """ Generate a random array with a fixed seed. """ old_seed = np.random.seed() np.random.seed(seed) out = np.random.rand(size) np.random.seed(old_seed) return out
python
def const_rand(size, seed=23980): """ Generate a random array with a fixed seed. """ old_seed = np.random.seed() np.random.seed(seed) out = np.random.rand(size) np.random.seed(old_seed) return out
[ "def", "const_rand", "(", "size", ",", "seed", "=", "23980", ")", ":", "old_seed", "=", "np", ".", "random", ".", "seed", "(", ")", "np", ".", "random", ".", "seed", "(", "seed", ")", "out", "=", "np", ".", "random", ".", "rand", "(", "size", "...
Generate a random array with a fixed seed.
[ "Generate", "a", "random", "array", "with", "a", "fixed", "seed", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/measures.py#L401-L408
train
slundberg/shap
shap/benchmark/measures.py
const_shuffle
def const_shuffle(arr, seed=23980): """ Shuffle an array in-place with a fixed seed. """ old_seed = np.random.seed() np.random.seed(seed) np.random.shuffle(arr) np.random.seed(old_seed)
python
def const_shuffle(arr, seed=23980): """ Shuffle an array in-place with a fixed seed. """ old_seed = np.random.seed() np.random.seed(seed) np.random.shuffle(arr) np.random.seed(old_seed)
[ "def", "const_shuffle", "(", "arr", ",", "seed", "=", "23980", ")", ":", "old_seed", "=", "np", ".", "random", ".", "seed", "(", ")", "np", ".", "random", ".", "seed", "(", "seed", ")", "np", ".", "random", ".", "shuffle", "(", "arr", ")", "np", ...
Shuffle an array in-place with a fixed seed.
[ "Shuffle", "an", "array", "in", "-", "place", "with", "a", "fixed", "seed", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/measures.py#L410-L416
train
slundberg/shap
shap/explainers/mimic.py
MimicExplainer.shap_values
def shap_values(self, X, **kwargs): """ Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame A matrix of samples (# samples x # features) on which to explain the model's output. Returns ------- For ...
python
def shap_values(self, X, **kwargs): """ Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame A matrix of samples (# samples x # features) on which to explain the model's output. Returns ------- For ...
[ "def", "shap_values", "(", "self", ",", "X", ",", "*", "*", "kwargs", ")", ":", "phi", "=", "None", "if", "self", ".", "mimic_model_type", "==", "\"xgboost\"", ":", "if", "not", "str", "(", "type", "(", "X", ")", ")", ".", "endswith", "(", "\"xgboo...
Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame A matrix of samples (# samples x # features) on which to explain the model's output. Returns ------- For a models with a single output this returns a mat...
[ "Estimate", "the", "SHAP", "values", "for", "a", "set", "of", "samples", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/mimic.py#L75-L102
train
slundberg/shap
shap/plots/image.py
image_plot
def image_plot(shap_values, x, labels=None, show=True, width=20, aspect=0.2, hspace=0.2, labelpad=None): """ Plots SHAP values for image inputs. """ multi_output = True if type(shap_values) != list: multi_output = False shap_values = [shap_values] # make sure labels if labels i...
python
def image_plot(shap_values, x, labels=None, show=True, width=20, aspect=0.2, hspace=0.2, labelpad=None): """ Plots SHAP values for image inputs. """ multi_output = True if type(shap_values) != list: multi_output = False shap_values = [shap_values] # make sure labels if labels i...
[ "def", "image_plot", "(", "shap_values", ",", "x", ",", "labels", "=", "None", ",", "show", "=", "True", ",", "width", "=", "20", ",", "aspect", "=", "0.2", ",", "hspace", "=", "0.2", ",", "labelpad", "=", "None", ")", ":", "multi_output", "=", "Tr...
Plots SHAP values for image inputs.
[ "Plots", "SHAP", "values", "for", "image", "inputs", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/image.py#L10-L72
train
slundberg/shap
shap/common.py
hclust_ordering
def hclust_ordering(X, metric="sqeuclidean"): """ A leaf ordering is under-defined, this picks the ordering that keeps nearby samples similar. """ # compute a hierarchical clustering D = sp.spatial.distance.pdist(X, metric) cluster_matrix = sp.cluster.hierarchy.complete(D) # merge clus...
python
def hclust_ordering(X, metric="sqeuclidean"): """ A leaf ordering is under-defined, this picks the ordering that keeps nearby samples similar. """ # compute a hierarchical clustering D = sp.spatial.distance.pdist(X, metric) cluster_matrix = sp.cluster.hierarchy.complete(D) # merge clus...
[ "def", "hclust_ordering", "(", "X", ",", "metric", "=", "\"sqeuclidean\"", ")", ":", "# compute a hierarchical clustering", "D", "=", "sp", ".", "spatial", ".", "distance", ".", "pdist", "(", "X", ",", "metric", ")", "cluster_matrix", "=", "sp", ".", "cluste...
A leaf ordering is under-defined, this picks the ordering that keeps nearby samples similar.
[ "A", "leaf", "ordering", "is", "under", "-", "defined", "this", "picks", "the", "ordering", "that", "keeps", "nearby", "samples", "similar", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/common.py#L215-L247
train
slundberg/shap
shap/common.py
approximate_interactions
def approximate_interactions(index, shap_values, X, feature_names=None): """ Order other features by how much interaction they seem to have with the feature at the given index. This just bins the SHAP values for a feature along that feature's value. For true Shapley interaction index values for SHAP see th...
python
def approximate_interactions(index, shap_values, X, feature_names=None): """ Order other features by how much interaction they seem to have with the feature at the given index. This just bins the SHAP values for a feature along that feature's value. For true Shapley interaction index values for SHAP see th...
[ "def", "approximate_interactions", "(", "index", ",", "shap_values", ",", "X", ",", "feature_names", "=", "None", ")", ":", "# convert from DataFrames if we got any", "if", "str", "(", "type", "(", "X", ")", ")", ".", "endswith", "(", "\"'pandas.core.frame.DataFra...
Order other features by how much interaction they seem to have with the feature at the given index. This just bins the SHAP values for a feature along that feature's value. For true Shapley interaction index values for SHAP see the interaction_contribs option implemented in XGBoost.
[ "Order", "other", "features", "by", "how", "much", "interaction", "they", "seem", "to", "have", "with", "the", "feature", "at", "the", "given", "index", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/common.py#L271-L318
train
slundberg/shap
shap/benchmark/plots.py
_human_score_map
def _human_score_map(human_consensus, methods_attrs): """ Converts human agreement differences to numerical scores for coloring. """ v = 1 - min(np.sum(np.abs(methods_attrs - human_consensus)) / (np.abs(human_consensus).sum() + 1), 1.0) return v
python
def _human_score_map(human_consensus, methods_attrs): """ Converts human agreement differences to numerical scores for coloring. """ v = 1 - min(np.sum(np.abs(methods_attrs - human_consensus)) / (np.abs(human_consensus).sum() + 1), 1.0) return v
[ "def", "_human_score_map", "(", "human_consensus", ",", "methods_attrs", ")", ":", "v", "=", "1", "-", "min", "(", "np", ".", "sum", "(", "np", ".", "abs", "(", "methods_attrs", "-", "human_consensus", ")", ")", "/", "(", "np", ".", "abs", "(", "huma...
Converts human agreement differences to numerical scores for coloring.
[ "Converts", "human", "agreement", "differences", "to", "numerical", "scores", "for", "coloring", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/plots.py#L370-L375
train
slundberg/shap
shap/plots/force_matplotlib.py
draw_bars
def draw_bars(out_value, features, feature_type, width_separators, width_bar): """Draw the bars and separators.""" rectangle_list = [] separator_list = [] pre_val = out_value for index, features in zip(range(len(features)), features): if feature_type == 'positive': left_boun...
python
def draw_bars(out_value, features, feature_type, width_separators, width_bar): """Draw the bars and separators.""" rectangle_list = [] separator_list = [] pre_val = out_value for index, features in zip(range(len(features)), features): if feature_type == 'positive': left_boun...
[ "def", "draw_bars", "(", "out_value", ",", "features", ",", "feature_type", ",", "width_separators", ",", "width_bar", ")", ":", "rectangle_list", "=", "[", "]", "separator_list", "=", "[", "]", "pre_val", "=", "out_value", "for", "index", ",", "features", "...
Draw the bars and separators.
[ "Draw", "the", "bars", "and", "separators", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/force_matplotlib.py#L15-L77
train
slundberg/shap
shap/plots/force_matplotlib.py
format_data
def format_data(data): """Format data.""" # Format negative features neg_features = np.array([[data['features'][x]['effect'], data['features'][x]['value'], data['featureNames'][x]] for x in data['features'].keys() if da...
python
def format_data(data): """Format data.""" # Format negative features neg_features = np.array([[data['features'][x]['effect'], data['features'][x]['value'], data['featureNames'][x]] for x in data['features'].keys() if da...
[ "def", "format_data", "(", "data", ")", ":", "# Format negative features", "neg_features", "=", "np", ".", "array", "(", "[", "[", "data", "[", "'features'", "]", "[", "x", "]", "[", "'effect'", "]", ",", "data", "[", "'features'", "]", "[", "x", "]", ...
Format data.
[ "Format", "data", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/force_matplotlib.py#L199-L253
train
slundberg/shap
shap/plots/force_matplotlib.py
draw_additive_plot
def draw_additive_plot(data, figsize, show, text_rotation=0): """Draw additive plot.""" # Turn off interactive plot if show == False: plt.ioff() # Format data neg_features, total_neg, pos_features, total_pos = format_data(data) # Compute overall metrics base_value = data['b...
python
def draw_additive_plot(data, figsize, show, text_rotation=0): """Draw additive plot.""" # Turn off interactive plot if show == False: plt.ioff() # Format data neg_features, total_neg, pos_features, total_pos = format_data(data) # Compute overall metrics base_value = data['b...
[ "def", "draw_additive_plot", "(", "data", ",", "figsize", ",", "show", ",", "text_rotation", "=", "0", ")", ":", "# Turn off interactive plot", "if", "show", "==", "False", ":", "plt", ".", "ioff", "(", ")", "# Format data", "neg_features", ",", "total_neg", ...
Draw additive plot.
[ "Draw", "additive", "plot", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/force_matplotlib.py#L333-L397
train
slundberg/shap
setup.py
try_run_setup
def try_run_setup(**kwargs): """ Fails gracefully when various install steps don't work. """ try: run_setup(**kwargs) except Exception as e: print(str(e)) if "xgboost" in str(e).lower(): kwargs["test_xgboost"] = False print("Couldn't install XGBoost for t...
python
def try_run_setup(**kwargs): """ Fails gracefully when various install steps don't work. """ try: run_setup(**kwargs) except Exception as e: print(str(e)) if "xgboost" in str(e).lower(): kwargs["test_xgboost"] = False print("Couldn't install XGBoost for t...
[ "def", "try_run_setup", "(", "*", "*", "kwargs", ")", ":", "try", ":", "run_setup", "(", "*", "*", "kwargs", ")", "except", "Exception", "as", "e", ":", "print", "(", "str", "(", "e", ")", ")", "if", "\"xgboost\"", "in", "str", "(", "e", ")", "."...
Fails gracefully when various install steps don't work.
[ "Fails", "gracefully", "when", "various", "install", "steps", "don", "t", "work", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/setup.py#L101-L122
train
slundberg/shap
shap/explainers/deep/deep_pytorch.py
deeplift_grad
def deeplift_grad(module, grad_input, grad_output): """The backward hook which computes the deeplift gradient for an nn.Module """ # first, get the module type module_type = module.__class__.__name__ # first, check the module is supported if module_type in op_handler: if op_handler[m...
python
def deeplift_grad(module, grad_input, grad_output): """The backward hook which computes the deeplift gradient for an nn.Module """ # first, get the module type module_type = module.__class__.__name__ # first, check the module is supported if module_type in op_handler: if op_handler[m...
[ "def", "deeplift_grad", "(", "module", ",", "grad_input", ",", "grad_output", ")", ":", "# first, get the module type", "module_type", "=", "module", ".", "__class__", ".", "__name__", "# first, check the module is supported", "if", "module_type", "in", "op_handler", ":...
The backward hook which computes the deeplift gradient for an nn.Module
[ "The", "backward", "hook", "which", "computes", "the", "deeplift", "gradient", "for", "an", "nn", ".", "Module" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_pytorch.py#L194-L206
train
slundberg/shap
shap/explainers/deep/deep_pytorch.py
add_interim_values
def add_interim_values(module, input, output): """The forward hook used to save interim tensors, detached from the graph. Used to calculate the multipliers """ try: del module.x except AttributeError: pass try: del module.y except AttributeError: pass modu...
python
def add_interim_values(module, input, output): """The forward hook used to save interim tensors, detached from the graph. Used to calculate the multipliers """ try: del module.x except AttributeError: pass try: del module.y except AttributeError: pass modu...
[ "def", "add_interim_values", "(", "module", ",", "input", ",", "output", ")", ":", "try", ":", "del", "module", ".", "x", "except", "AttributeError", ":", "pass", "try", ":", "del", "module", ".", "y", "except", "AttributeError", ":", "pass", "module_type"...
The forward hook used to save interim tensors, detached from the graph. Used to calculate the multipliers
[ "The", "forward", "hook", "used", "to", "save", "interim", "tensors", "detached", "from", "the", "graph", ".", "Used", "to", "calculate", "the", "multipliers" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_pytorch.py#L209-L245
train
slundberg/shap
shap/explainers/deep/deep_pytorch.py
get_target_input
def get_target_input(module, input, output): """A forward hook which saves the tensor - attached to its graph. Used if we want to explain the interim outputs of a model """ try: del module.target_input except AttributeError: pass setattr(module, 'target_input', input)
python
def get_target_input(module, input, output): """A forward hook which saves the tensor - attached to its graph. Used if we want to explain the interim outputs of a model """ try: del module.target_input except AttributeError: pass setattr(module, 'target_input', input)
[ "def", "get_target_input", "(", "module", ",", "input", ",", "output", ")", ":", "try", ":", "del", "module", ".", "target_input", "except", "AttributeError", ":", "pass", "setattr", "(", "module", ",", "'target_input'", ",", "input", ")" ]
A forward hook which saves the tensor - attached to its graph. Used if we want to explain the interim outputs of a model
[ "A", "forward", "hook", "which", "saves", "the", "tensor", "-", "attached", "to", "its", "graph", ".", "Used", "if", "we", "want", "to", "explain", "the", "interim", "outputs", "of", "a", "model" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_pytorch.py#L248-L256
train
slundberg/shap
shap/explainers/deep/deep_pytorch.py
PyTorchDeepExplainer.add_handles
def add_handles(self, model, forward_handle, backward_handle): """ Add handles to all non-container layers in the model. Recursively for non-container layers """ handles_list = [] for child in model.children(): if 'nn.modules.container' in str(type(child)): ...
python
def add_handles(self, model, forward_handle, backward_handle): """ Add handles to all non-container layers in the model. Recursively for non-container layers """ handles_list = [] for child in model.children(): if 'nn.modules.container' in str(type(child)): ...
[ "def", "add_handles", "(", "self", ",", "model", ",", "forward_handle", ",", "backward_handle", ")", ":", "handles_list", "=", "[", "]", "for", "child", "in", "model", ".", "children", "(", ")", ":", "if", "'nn.modules.container'", "in", "str", "(", "type"...
Add handles to all non-container layers in the model. Recursively for non-container layers
[ "Add", "handles", "to", "all", "non", "-", "container", "layers", "in", "the", "model", ".", "Recursively", "for", "non", "-", "container", "layers" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_pytorch.py#L64-L76
train
slundberg/shap
shap/explainers/deep/deep_pytorch.py
PyTorchDeepExplainer.remove_attributes
def remove_attributes(self, model): """ Removes the x and y attributes which were added by the forward handles Recursively searches for non-container layers """ for child in model.children(): if 'nn.modules.container' in str(type(child)): self.remove_a...
python
def remove_attributes(self, model): """ Removes the x and y attributes which were added by the forward handles Recursively searches for non-container layers """ for child in model.children(): if 'nn.modules.container' in str(type(child)): self.remove_a...
[ "def", "remove_attributes", "(", "self", ",", "model", ")", ":", "for", "child", "in", "model", ".", "children", "(", ")", ":", "if", "'nn.modules.container'", "in", "str", "(", "type", "(", "child", ")", ")", ":", "self", ".", "remove_attributes", "(", ...
Removes the x and y attributes which were added by the forward handles Recursively searches for non-container layers
[ "Removes", "the", "x", "and", "y", "attributes", "which", "were", "added", "by", "the", "forward", "handles", "Recursively", "searches", "for", "non", "-", "container", "layers" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_pytorch.py#L78-L94
train
slundberg/shap
shap/explainers/tree.py
get_xgboost_json
def get_xgboost_json(model): """ This gets a JSON dump of an XGBoost model while ensuring the features names are their indexes. """ fnames = model.feature_names model.feature_names = None json_trees = model.get_dump(with_stats=True, dump_format="json") model.feature_names = fnames # this fi...
python
def get_xgboost_json(model): """ This gets a JSON dump of an XGBoost model while ensuring the features names are their indexes. """ fnames = model.feature_names model.feature_names = None json_trees = model.get_dump(with_stats=True, dump_format="json") model.feature_names = fnames # this fi...
[ "def", "get_xgboost_json", "(", "model", ")", ":", "fnames", "=", "model", ".", "feature_names", "model", ".", "feature_names", "=", "None", "json_trees", "=", "model", ".", "get_dump", "(", "with_stats", "=", "True", ",", "dump_format", "=", "\"json\"", ")"...
This gets a JSON dump of an XGBoost model while ensuring the features names are their indexes.
[ "This", "gets", "a", "JSON", "dump", "of", "an", "XGBoost", "model", "while", "ensuring", "the", "features", "names", "are", "their", "indexes", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/tree.py#L907-L919
train
slundberg/shap
shap/explainers/tree.py
TreeExplainer.__dynamic_expected_value
def __dynamic_expected_value(self, y): """ This computes the expected value conditioned on the given label value. """ return self.model.predict(self.data, np.ones(self.data.shape[0]) * y, output=self.model_output).mean(0)
python
def __dynamic_expected_value(self, y): """ This computes the expected value conditioned on the given label value. """ return self.model.predict(self.data, np.ones(self.data.shape[0]) * y, output=self.model_output).mean(0)
[ "def", "__dynamic_expected_value", "(", "self", ",", "y", ")", ":", "return", "self", ".", "model", ".", "predict", "(", "self", ".", "data", ",", "np", ".", "ones", "(", "self", ".", "data", ".", "shape", "[", "0", "]", ")", "*", "y", ",", "outp...
This computes the expected value conditioned on the given label value.
[ "This", "computes", "the", "expected", "value", "conditioned", "on", "the", "given", "label", "value", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/tree.py#L125-L129
train
slundberg/shap
shap/explainers/tree.py
TreeExplainer.shap_values
def shap_values(self, X, y=None, tree_limit=None, approximate=False): """ Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array, pandas.DataFrame or catboost.Pool (for catboost) A matrix of samples (# samples x # features) on which to explain t...
python
def shap_values(self, X, y=None, tree_limit=None, approximate=False): """ Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array, pandas.DataFrame or catboost.Pool (for catboost) A matrix of samples (# samples x # features) on which to explain t...
[ "def", "shap_values", "(", "self", ",", "X", ",", "y", "=", "None", ",", "tree_limit", "=", "None", ",", "approximate", "=", "False", ")", ":", "# see if we have a default tree_limit in place.", "if", "tree_limit", "is", "None", ":", "tree_limit", "=", "-", ...
Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array, pandas.DataFrame or catboost.Pool (for catboost) A matrix of samples (# samples x # features) on which to explain the model's output. y : numpy.array An array of label values f...
[ "Estimate", "the", "SHAP", "values", "for", "a", "set", "of", "samples", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/tree.py#L131-L263
train
slundberg/shap
shap/explainers/tree.py
TreeExplainer.shap_interaction_values
def shap_interaction_values(self, X, y=None, tree_limit=None): """ Estimate the SHAP interaction values for a set of samples. Parameters ---------- X : numpy.array, pandas.DataFrame or catboost.Pool (for catboost) A matrix of samples (# samples x # features) on which to expl...
python
def shap_interaction_values(self, X, y=None, tree_limit=None): """ Estimate the SHAP interaction values for a set of samples. Parameters ---------- X : numpy.array, pandas.DataFrame or catboost.Pool (for catboost) A matrix of samples (# samples x # features) on which to expl...
[ "def", "shap_interaction_values", "(", "self", ",", "X", ",", "y", "=", "None", ",", "tree_limit", "=", "None", ")", ":", "assert", "self", ".", "model_output", "==", "\"margin\"", ",", "\"Only model_output = \\\"margin\\\" is supported for SHAP interaction values right...
Estimate the SHAP interaction values for a set of samples. Parameters ---------- X : numpy.array, pandas.DataFrame or catboost.Pool (for catboost) A matrix of samples (# samples x # features) on which to explain the model's output. y : numpy.array An array of la...
[ "Estimate", "the", "SHAP", "interaction", "values", "for", "a", "set", "of", "samples", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/tree.py#L265-L358
train
slundberg/shap
shap/explainers/tree.py
TreeEnsemble.get_transform
def get_transform(self, model_output): """ A consistent interface to make predictions from this model. """ if model_output == "margin": transform = "identity" elif model_output == "probability": if self.tree_output == "log_odds": transform = "logis...
python
def get_transform(self, model_output): """ A consistent interface to make predictions from this model. """ if model_output == "margin": transform = "identity" elif model_output == "probability": if self.tree_output == "log_odds": transform = "logis...
[ "def", "get_transform", "(", "self", ",", "model_output", ")", ":", "if", "model_output", "==", "\"margin\"", ":", "transform", "=", "\"identity\"", "elif", "model_output", "==", "\"probability\"", ":", "if", "self", ".", "tree_output", "==", "\"log_odds\"", ":"...
A consistent interface to make predictions from this model.
[ "A", "consistent", "interface", "to", "make", "predictions", "from", "this", "model", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/tree.py#L633-L653
train
slundberg/shap
shap/explainers/tree.py
TreeEnsemble.predict
def predict(self, X, y=None, output="margin", tree_limit=None): """ A consistent interface to make predictions from this model. Parameters ---------- tree_limit : None (default) or int Limit the number of trees used by the model. By default None means no use the limit of th...
python
def predict(self, X, y=None, output="margin", tree_limit=None): """ A consistent interface to make predictions from this model. Parameters ---------- tree_limit : None (default) or int Limit the number of trees used by the model. By default None means no use the limit of th...
[ "def", "predict", "(", "self", ",", "X", ",", "y", "=", "None", ",", "output", "=", "\"margin\"", ",", "tree_limit", "=", "None", ")", ":", "# see if we have a default tree_limit in place.", "if", "tree_limit", "is", "None", ":", "tree_limit", "=", "-", "1",...
A consistent interface to make predictions from this model. Parameters ---------- tree_limit : None (default) or int Limit the number of trees used by the model. By default None means no use the limit of the original model, and -1 means no limit.
[ "A", "consistent", "interface", "to", "make", "predictions", "from", "this", "model", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/tree.py#L655-L716
train
slundberg/shap
shap/explainers/gradient.py
GradientExplainer.shap_values
def shap_values(self, X, nsamples=200, ranked_outputs=None, output_rank_order="max", rseed=None): """ Return the values for the model applied to X. Parameters ---------- X : list, if framework == 'tensorflow': numpy.array, or pandas.DataFrame if framework == 'pyt...
python
def shap_values(self, X, nsamples=200, ranked_outputs=None, output_rank_order="max", rseed=None): """ Return the values for the model applied to X. Parameters ---------- X : list, if framework == 'tensorflow': numpy.array, or pandas.DataFrame if framework == 'pyt...
[ "def", "shap_values", "(", "self", ",", "X", ",", "nsamples", "=", "200", ",", "ranked_outputs", "=", "None", ",", "output_rank_order", "=", "\"max\"", ",", "rseed", "=", "None", ")", ":", "return", "self", ".", "explainer", ".", "shap_values", "(", "X",...
Return the values for the model applied to X. Parameters ---------- X : list, if framework == 'tensorflow': numpy.array, or pandas.DataFrame if framework == 'pytorch': torch.tensor A tensor (or list of tensors) of samples (where X.shape[0] == # samples) on wh...
[ "Return", "the", "values", "for", "the", "model", "applied", "to", "X", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/gradient.py#L75-L112
train
slundberg/shap
shap/plots/force.py
force_plot
def force_plot(base_value, shap_values, features=None, feature_names=None, out_names=None, link="identity", plot_cmap="RdBu", matplotlib=False, show=True, figsize=(20,3), ordering_keys=None, ordering_keys_time_format=None, text_rotation=0): """ Visualize the given SHAP values with an a...
python
def force_plot(base_value, shap_values, features=None, feature_names=None, out_names=None, link="identity", plot_cmap="RdBu", matplotlib=False, show=True, figsize=(20,3), ordering_keys=None, ordering_keys_time_format=None, text_rotation=0): """ Visualize the given SHAP values with an a...
[ "def", "force_plot", "(", "base_value", ",", "shap_values", ",", "features", "=", "None", ",", "feature_names", "=", "None", ",", "out_names", "=", "None", ",", "link", "=", "\"identity\"", ",", "plot_cmap", "=", "\"RdBu\"", ",", "matplotlib", "=", "False", ...
Visualize the given SHAP values with an additive force layout. Parameters ---------- base_value : float This is the reference value that the feature contributions start from. For SHAP values it should be the value of explainer.expected_value. shap_values : numpy.array Matri...
[ "Visualize", "the", "given", "SHAP", "values", "with", "an", "additive", "force", "layout", ".", "Parameters", "----------", "base_value", ":", "float", "This", "is", "the", "reference", "value", "that", "the", "feature", "contributions", "start", "from", ".", ...
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/force.py#L27-L171
train
slundberg/shap
shap/plots/force.py
save_html
def save_html(out_file, plot_html): """ Save html plots to an output file. """ internal_open = False if type(out_file) == str: out_file = open(out_file, "w") internal_open = True out_file.write("<html><head><script>\n") # dump the js code bundle_path = os.path.join(os.path....
python
def save_html(out_file, plot_html): """ Save html plots to an output file. """ internal_open = False if type(out_file) == str: out_file = open(out_file, "w") internal_open = True out_file.write("<html><head><script>\n") # dump the js code bundle_path = os.path.join(os.path....
[ "def", "save_html", "(", "out_file", ",", "plot_html", ")", ":", "internal_open", "=", "False", "if", "type", "(", "out_file", ")", "==", "str", ":", "out_file", "=", "open", "(", "out_file", ",", "\"w\"", ")", "internal_open", "=", "True", "out_file", "...
Save html plots to an output file.
[ "Save", "html", "plots", "to", "an", "output", "file", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/force.py#L217-L239
train
slundberg/shap
shap/explainers/deep/deep_tf.py
tensors_blocked_by_false
def tensors_blocked_by_false(ops): """ Follows a set of ops assuming their value is False and find blocked Switch paths. This is used to prune away parts of the model graph that are only used during the training phase (like dropout, batch norm, etc.). """ blocked = [] def recurse(op): i...
python
def tensors_blocked_by_false(ops): """ Follows a set of ops assuming their value is False and find blocked Switch paths. This is used to prune away parts of the model graph that are only used during the training phase (like dropout, batch norm, etc.). """ blocked = [] def recurse(op): i...
[ "def", "tensors_blocked_by_false", "(", "ops", ")", ":", "blocked", "=", "[", "]", "def", "recurse", "(", "op", ")", ":", "if", "op", ".", "type", "==", "\"Switch\"", ":", "blocked", ".", "append", "(", "op", ".", "outputs", "[", "1", "]", ")", "# ...
Follows a set of ops assuming their value is False and find blocked Switch paths. This is used to prune away parts of the model graph that are only used during the training phase (like dropout, batch norm, etc.).
[ "Follows", "a", "set", "of", "ops", "assuming", "their", "value", "is", "False", "and", "find", "blocked", "Switch", "paths", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_tf.py#L290-L307
train
slundberg/shap
shap/explainers/deep/deep_tf.py
softmax
def softmax(explainer, op, *grads): """ Just decompose softmax into its components and recurse, we can handle all of them :) We assume the 'axis' is the last dimension because the TF codebase swaps the 'axis' to the last dimension before the softmax op if 'axis' is not already the last dimension. We al...
python
def softmax(explainer, op, *grads): """ Just decompose softmax into its components and recurse, we can handle all of them :) We assume the 'axis' is the last dimension because the TF codebase swaps the 'axis' to the last dimension before the softmax op if 'axis' is not already the last dimension. We al...
[ "def", "softmax", "(", "explainer", ",", "op", ",", "*", "grads", ")", ":", "in0", "=", "op", ".", "inputs", "[", "0", "]", "in0_max", "=", "tf", ".", "reduce_max", "(", "in0", ",", "axis", "=", "-", "1", ",", "keepdims", "=", "True", ",", "nam...
Just decompose softmax into its components and recurse, we can handle all of them :) We assume the 'axis' is the last dimension because the TF codebase swaps the 'axis' to the last dimension before the softmax op if 'axis' is not already the last dimension. We also don't subtract the max before tf.exp for ...
[ "Just", "decompose", "softmax", "into", "its", "components", "and", "recurse", "we", "can", "handle", "all", "of", "them", ":", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_tf.py#L335-L363
train
slundberg/shap
shap/explainers/deep/deep_tf.py
TFDeepExplainer._variable_inputs
def _variable_inputs(self, op): """ Return which inputs of this operation are variable (i.e. depend on the model inputs). """ if op.name not in self._vinputs: self._vinputs[op.name] = np.array([t.op in self.between_ops or t in self.model_inputs for t in op.inputs]) return sel...
python
def _variable_inputs(self, op): """ Return which inputs of this operation are variable (i.e. depend on the model inputs). """ if op.name not in self._vinputs: self._vinputs[op.name] = np.array([t.op in self.between_ops or t in self.model_inputs for t in op.inputs]) return sel...
[ "def", "_variable_inputs", "(", "self", ",", "op", ")", ":", "if", "op", ".", "name", "not", "in", "self", ".", "_vinputs", ":", "self", ".", "_vinputs", "[", "op", ".", "name", "]", "=", "np", ".", "array", "(", "[", "t", ".", "op", "in", "sel...
Return which inputs of this operation are variable (i.e. depend on the model inputs).
[ "Return", "which", "inputs", "of", "this", "operation", "are", "variable", "(", "i", ".", "e", ".", "depend", "on", "the", "model", "inputs", ")", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_tf.py#L171-L176
train
slundberg/shap
shap/explainers/deep/deep_tf.py
TFDeepExplainer.phi_symbolic
def phi_symbolic(self, i): """ Get the SHAP value computation graph for a given model output. """ if self.phi_symbolics[i] is None: # replace the gradients for all the non-linear activations # we do this by hacking our way into the registry (TODO: find a public API for t...
python
def phi_symbolic(self, i): """ Get the SHAP value computation graph for a given model output. """ if self.phi_symbolics[i] is None: # replace the gradients for all the non-linear activations # we do this by hacking our way into the registry (TODO: find a public API for t...
[ "def", "phi_symbolic", "(", "self", ",", "i", ")", ":", "if", "self", ".", "phi_symbolics", "[", "i", "]", "is", "None", ":", "# replace the gradients for all the non-linear activations", "# we do this by hacking our way into the registry (TODO: find a public API for this if it...
Get the SHAP value computation graph for a given model output.
[ "Get", "the", "SHAP", "value", "computation", "graph", "for", "a", "given", "model", "output", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_tf.py#L178-L214
train
slundberg/shap
shap/explainers/deep/deep_tf.py
TFDeepExplainer.run
def run(self, out, model_inputs, X): """ Runs the model while also setting the learning phase flags to False. """ feed_dict = dict(zip(model_inputs, X)) for t in self.learning_phase_flags: feed_dict[t] = False return self.session.run(out, feed_dict)
python
def run(self, out, model_inputs, X): """ Runs the model while also setting the learning phase flags to False. """ feed_dict = dict(zip(model_inputs, X)) for t in self.learning_phase_flags: feed_dict[t] = False return self.session.run(out, feed_dict)
[ "def", "run", "(", "self", ",", "out", ",", "model_inputs", ",", "X", ")", ":", "feed_dict", "=", "dict", "(", "zip", "(", "model_inputs", ",", "X", ")", ")", "for", "t", "in", "self", ".", "learning_phase_flags", ":", "feed_dict", "[", "t", "]", "...
Runs the model while also setting the learning phase flags to False.
[ "Runs", "the", "model", "while", "also", "setting", "the", "learning", "phase", "flags", "to", "False", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_tf.py#L276-L282
train
slundberg/shap
shap/explainers/deep/deep_tf.py
TFDeepExplainer.custom_grad
def custom_grad(self, op, *grads): """ Passes a gradient op creation request to the correct handler. """ return op_handlers[op.type](self, op, *grads)
python
def custom_grad(self, op, *grads): """ Passes a gradient op creation request to the correct handler. """ return op_handlers[op.type](self, op, *grads)
[ "def", "custom_grad", "(", "self", ",", "op", ",", "*", "grads", ")", ":", "return", "op_handlers", "[", "op", ".", "type", "]", "(", "self", ",", "op", ",", "*", "grads", ")" ]
Passes a gradient op creation request to the correct handler.
[ "Passes", "a", "gradient", "op", "creation", "request", "to", "the", "correct", "handler", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/deep/deep_tf.py#L284-L287
train
slundberg/shap
shap/benchmark/experiments.py
run_remote_experiments
def run_remote_experiments(experiments, thread_hosts, rate_limit=10): """ Use ssh to run the experiments on remote machines in parallel. Parameters ---------- experiments : iterable Output of shap.benchmark.experiments(...). thread_hosts : list of strings Each host has the format "...
python
def run_remote_experiments(experiments, thread_hosts, rate_limit=10): """ Use ssh to run the experiments on remote machines in parallel. Parameters ---------- experiments : iterable Output of shap.benchmark.experiments(...). thread_hosts : list of strings Each host has the format "...
[ "def", "run_remote_experiments", "(", "experiments", ",", "thread_hosts", ",", "rate_limit", "=", "10", ")", ":", "global", "ssh_conn_per_min_limit", "ssh_conn_per_min_limit", "=", "rate_limit", "# first we kill any remaining workers from previous runs", "# note we don't check_ca...
Use ssh to run the experiments on remote machines in parallel. Parameters ---------- experiments : iterable Output of shap.benchmark.experiments(...). thread_hosts : list of strings Each host has the format "host_name:path_to_python_binary" and can appear multiple times in the ...
[ "Use", "ssh", "to", "run", "the", "experiments", "on", "remote", "machines", "in", "parallel", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/experiments.py#L322-L372
train
slundberg/shap
shap/plots/monitoring.py
monitoring_plot
def monitoring_plot(ind, shap_values, features, feature_names=None): """ Create a SHAP monitoring plot. (Note this function is preliminary and subject to change!!) A SHAP monitoring plot is meant to display the behavior of a model over time. Often the shap_values given to this plot explain the loss...
python
def monitoring_plot(ind, shap_values, features, feature_names=None): """ Create a SHAP monitoring plot. (Note this function is preliminary and subject to change!!) A SHAP monitoring plot is meant to display the behavior of a model over time. Often the shap_values given to this plot explain the loss...
[ "def", "monitoring_plot", "(", "ind", ",", "shap_values", ",", "features", ",", "feature_names", "=", "None", ")", ":", "if", "str", "(", "type", "(", "features", ")", ")", ".", "endswith", "(", "\"'pandas.core.frame.DataFrame'>\"", ")", ":", "if", "feature_...
Create a SHAP monitoring plot. (Note this function is preliminary and subject to change!!) A SHAP monitoring plot is meant to display the behavior of a model over time. Often the shap_values given to this plot explain the loss of a model, so changes in a feature's impact on the model's loss over ...
[ "Create", "a", "SHAP", "monitoring", "plot", ".", "(", "Note", "this", "function", "is", "preliminary", "and", "subject", "to", "change!!", ")", "A", "SHAP", "monitoring", "plot", "is", "meant", "to", "display", "the", "behavior", "of", "a", "model", "over...
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/monitoring.py#L20-L78
train
slundberg/shap
shap/explainers/kernel.py
kmeans
def kmeans(X, k, round_values=True): """ Summarize a dataset with k mean samples weighted by the number of data points they each represent. Parameters ---------- X : numpy.array or pandas.DataFrame Matrix of data samples to summarize (# samples x # features) k : int Number of m...
python
def kmeans(X, k, round_values=True): """ Summarize a dataset with k mean samples weighted by the number of data points they each represent. Parameters ---------- X : numpy.array or pandas.DataFrame Matrix of data samples to summarize (# samples x # features) k : int Number of m...
[ "def", "kmeans", "(", "X", ",", "k", ",", "round_values", "=", "True", ")", ":", "group_names", "=", "[", "str", "(", "i", ")", "for", "i", "in", "range", "(", "X", ".", "shape", "[", "1", "]", ")", "]", "if", "str", "(", "type", "(", "X", ...
Summarize a dataset with k mean samples weighted by the number of data points they each represent. Parameters ---------- X : numpy.array or pandas.DataFrame Matrix of data samples to summarize (# samples x # features) k : int Number of means to use for approximation. round_val...
[ "Summarize", "a", "dataset", "with", "k", "mean", "samples", "weighted", "by", "the", "number", "of", "data", "points", "they", "each", "represent", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/kernel.py#L18-L50
train
slundberg/shap
shap/explainers/kernel.py
KernelExplainer.shap_values
def shap_values(self, X, **kwargs): """ Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame or any scipy.sparse matrix A matrix of samples (# samples x # features) on which to explain the model's output. nsamples ...
python
def shap_values(self, X, **kwargs): """ Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame or any scipy.sparse matrix A matrix of samples (# samples x # features) on which to explain the model's output. nsamples ...
[ "def", "shap_values", "(", "self", ",", "X", ",", "*", "*", "kwargs", ")", ":", "# convert dataframes", "if", "str", "(", "type", "(", "X", ")", ")", ".", "endswith", "(", "\"pandas.core.series.Series'>\"", ")", ":", "X", "=", "X", ".", "values", "elif...
Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame or any scipy.sparse matrix A matrix of samples (# samples x # features) on which to explain the model's output. nsamples : "auto" or int Number of times to r...
[ "Estimate", "the", "SHAP", "values", "for", "a", "set", "of", "samples", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/kernel.py#L132-L225
train
slundberg/shap
shap/plots/embedding.py
embedding_plot
def embedding_plot(ind, shap_values, feature_names=None, method="pca", alpha=1.0, show=True): """ Use the SHAP values as an embedding which we project to 2D for visualization. Parameters ---------- ind : int or string If this is an int it is the index of the feature to use to color the embeddin...
python
def embedding_plot(ind, shap_values, feature_names=None, method="pca", alpha=1.0, show=True): """ Use the SHAP values as an embedding which we project to 2D for visualization. Parameters ---------- ind : int or string If this is an int it is the index of the feature to use to color the embeddin...
[ "def", "embedding_plot", "(", "ind", ",", "shap_values", ",", "feature_names", "=", "None", ",", "method", "=", "\"pca\"", ",", "alpha", "=", "1.0", ",", "show", "=", "True", ")", ":", "if", "feature_names", "is", "None", ":", "feature_names", "=", "[", ...
Use the SHAP values as an embedding which we project to 2D for visualization. Parameters ---------- ind : int or string If this is an int it is the index of the feature to use to color the embedding. If this is a string it is either the name of the feature, or it can have the form "...
[ "Use", "the", "SHAP", "values", "as", "an", "embedding", "which", "we", "project", "to", "2D", "for", "visualization", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/embedding.py#L14-L78
train
slundberg/shap
shap/plots/dependence.py
dependence_plot
def dependence_plot(ind, shap_values, features, feature_names=None, display_features=None, interaction_index="auto", color="#1E88E5", axis_color="#333333", cmap=colors.red_blue, dot_size=16, x_jitter=0, alpha=1, title=None, xmin=None, xmax=None, show=True): ...
python
def dependence_plot(ind, shap_values, features, feature_names=None, display_features=None, interaction_index="auto", color="#1E88E5", axis_color="#333333", cmap=colors.red_blue, dot_size=16, x_jitter=0, alpha=1, title=None, xmin=None, xmax=None, show=True): ...
[ "def", "dependence_plot", "(", "ind", ",", "shap_values", ",", "features", ",", "feature_names", "=", "None", ",", "display_features", "=", "None", ",", "interaction_index", "=", "\"auto\"", ",", "color", "=", "\"#1E88E5\"", ",", "axis_color", "=", "\"#333333\""...
Create a SHAP dependence plot, colored by an interaction feature. Plots the value of the feature on the x-axis and the SHAP value of the same feature on the y-axis. This shows how the model depends on the given feature, and is like a richer extenstion of the classical parital dependence plots. Vertical dis...
[ "Create", "a", "SHAP", "dependence", "plot", "colored", "by", "an", "interaction", "feature", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/plots/dependence.py#L15-L275
train
slundberg/shap
shap/benchmark/metrics.py
runtime
def runtime(X, y, model_generator, method_name): """ Runtime transform = "negate" sort_order = 1 """ old_seed = np.random.seed() np.random.seed(3293) # average the method scores over several train/test splits method_reps = [] for i in range(1): X_train, X_test, y_train, _ =...
python
def runtime(X, y, model_generator, method_name): """ Runtime transform = "negate" sort_order = 1 """ old_seed = np.random.seed() np.random.seed(3293) # average the method scores over several train/test splits method_reps = [] for i in range(1): X_train, X_test, y_train, _ =...
[ "def", "runtime", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "old_seed", "=", "np", ".", "random", ".", "seed", "(", ")", "np", ".", "random", ".", "seed", "(", "3293", ")", "# average the method scores over several train/test ...
Runtime transform = "negate" sort_order = 1
[ "Runtime", "transform", "=", "negate", "sort_order", "=", "1" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L22-L54
train
slundberg/shap
shap/benchmark/metrics.py
local_accuracy
def local_accuracy(X, y, model_generator, method_name): """ Local Accuracy transform = "identity" sort_order = 2 """ def score_map(true, pred): """ Converts local accuracy from % of standard deviation to numerical scores for coloring. """ v = min(1.0, np.std(pred - true) / ...
python
def local_accuracy(X, y, model_generator, method_name): """ Local Accuracy transform = "identity" sort_order = 2 """ def score_map(true, pred): """ Converts local accuracy from % of standard deviation to numerical scores for coloring. """ v = min(1.0, np.std(pred - true) / ...
[ "def", "local_accuracy", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "def", "score_map", "(", "true", ",", "pred", ")", ":", "\"\"\" Converts local accuracy from % of standard deviation to numerical scores for coloring.\n \"\"\"", "v", ...
Local Accuracy transform = "identity" sort_order = 2
[ "Local", "Accuracy", "transform", "=", "identity", "sort_order", "=", "2" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L56-L90
train
slundberg/shap
shap/benchmark/metrics.py
keep_negative_mask
def keep_negative_mask(X, y, model_generator, method_name, num_fcounts=11): """ Keep Negative (mask) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 5 """ return __run_measure(measures.keep_mask, X, y, model_generator, method_n...
python
def keep_negative_mask(X, y, model_generator, method_name, num_fcounts=11): """ Keep Negative (mask) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 5 """ return __run_measure(measures.keep_mask, X, y, model_generator, method_n...
[ "def", "keep_negative_mask", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_mask", ",", "X", ",", "y", ",", "model_generator", ",", "method_name"...
Keep Negative (mask) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 5
[ "Keep", "Negative", "(", "mask", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "Negative", "mean", "model", "output", "transform", "=", "negate", "sort_order", "=", "5" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L135-L142
train
slundberg/shap
shap/benchmark/metrics.py
keep_absolute_mask__r2
def keep_absolute_mask__r2(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (mask) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 6 """ return __run_measure(measures.keep_mask, X, y, model_generator, method_name, 0, num_fcoun...
python
def keep_absolute_mask__r2(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (mask) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 6 """ return __run_measure(measures.keep_mask, X, y, model_generator, method_name, 0, num_fcoun...
[ "def", "keep_absolute_mask__r2", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_mask", ",", "X", ",", "y", ",", "model_generator", ",", "method_n...
Keep Absolute (mask) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 6
[ "Keep", "Absolute", "(", "mask", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "R^2", "transform", "=", "identity", "sort_order", "=", "6" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L144-L151
train
slundberg/shap
shap/benchmark/metrics.py
remove_positive_mask
def remove_positive_mask(X, y, model_generator, method_name, num_fcounts=11): """ Remove Positive (mask) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 7 """ return __run_measure(measures.remove_mask, X, y, model_generator,...
python
def remove_positive_mask(X, y, model_generator, method_name, num_fcounts=11): """ Remove Positive (mask) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 7 """ return __run_measure(measures.remove_mask, X, y, model_generator,...
[ "def", "remove_positive_mask", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_mask", ",", "X", ",", "y", ",", "model_generator", ",", "method_n...
Remove Positive (mask) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 7
[ "Remove", "Positive", "(", "mask", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "Negative", "mean", "model", "output", "transform", "=", "negate", "sort_order", "=", "7" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L162-L169
train
slundberg/shap
shap/benchmark/metrics.py
remove_absolute_mask__r2
def remove_absolute_mask__r2(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (mask) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 9 """ return __run_measure(measures.remove_mask, X, y, model_generator, method_name...
python
def remove_absolute_mask__r2(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (mask) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 9 """ return __run_measure(measures.remove_mask, X, y, model_generator, method_name...
[ "def", "remove_absolute_mask__r2", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_mask", ",", "X", ",", "y", ",", "model_generator", ",", "meth...
Remove Absolute (mask) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 9
[ "Remove", "Absolute", "(", "mask", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "1", "-", "R^2", "transform", "=", "one_minus", "sort_order", "=", "9" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L180-L187
train
slundberg/shap
shap/benchmark/metrics.py
keep_negative_resample
def keep_negative_resample(X, y, model_generator, method_name, num_fcounts=11): """ Keep Negative (resample) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 11 """ return __run_measure(measures.keep_resample, X, y, model_genera...
python
def keep_negative_resample(X, y, model_generator, method_name, num_fcounts=11): """ Keep Negative (resample) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 11 """ return __run_measure(measures.keep_resample, X, y, model_genera...
[ "def", "keep_negative_resample", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_resample", ",", "X", ",", "y", ",", "model_generator", ",", "meth...
Keep Negative (resample) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 11
[ "Keep", "Negative", "(", "resample", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "Negative", "mean", "model", "output", "transform", "=", "negate", "sort_order", "=", "11" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L207-L214
train
slundberg/shap
shap/benchmark/metrics.py
keep_absolute_resample__r2
def keep_absolute_resample__r2(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (resample) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 12 """ return __run_measure(measures.keep_resample, X, y, model_generator, method_name,...
python
def keep_absolute_resample__r2(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (resample) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 12 """ return __run_measure(measures.keep_resample, X, y, model_generator, method_name,...
[ "def", "keep_absolute_resample__r2", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_resample", ",", "X", ",", "y", ",", "model_generator", ",", "...
Keep Absolute (resample) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 12
[ "Keep", "Absolute", "(", "resample", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "R^2", "transform", "=", "identity", "sort_order", "=", "12" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L216-L223
train
slundberg/shap
shap/benchmark/metrics.py
keep_absolute_resample__roc_auc
def keep_absolute_resample__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (resample) xlabel = "Max fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 12 """ return __run_measure(measures.keep_resample, X, y, model_generator, met...
python
def keep_absolute_resample__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (resample) xlabel = "Max fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 12 """ return __run_measure(measures.keep_resample, X, y, model_generator, met...
[ "def", "keep_absolute_resample__roc_auc", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_resample", ",", "X", ",", "y", ",", "model_generator", ","...
Keep Absolute (resample) xlabel = "Max fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 12
[ "Keep", "Absolute", "(", "resample", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "ROC", "AUC", "transform", "=", "identity", "sort_order", "=", "12" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L225-L232
train
slundberg/shap
shap/benchmark/metrics.py
remove_positive_resample
def remove_positive_resample(X, y, model_generator, method_name, num_fcounts=11): """ Remove Positive (resample) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 13 """ return __run_measure(measures.remove_resample, X, y, mod...
python
def remove_positive_resample(X, y, model_generator, method_name, num_fcounts=11): """ Remove Positive (resample) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 13 """ return __run_measure(measures.remove_resample, X, y, mod...
[ "def", "remove_positive_resample", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_resample", ",", "X", ",", "y", ",", "model_generator", ",", "...
Remove Positive (resample) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 13
[ "Remove", "Positive", "(", "resample", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "Negative", "mean", "model", "output", "transform", "=", "negate", "sort_order", "=", "13" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L234-L241
train
slundberg/shap
shap/benchmark/metrics.py
remove_absolute_resample__r2
def remove_absolute_resample__r2(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (resample) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 15 """ return __run_measure(measures.remove_resample, X, y, model_generator...
python
def remove_absolute_resample__r2(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (resample) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 15 """ return __run_measure(measures.remove_resample, X, y, model_generator...
[ "def", "remove_absolute_resample__r2", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_resample", ",", "X", ",", "y", ",", "model_generator", ",",...
Remove Absolute (resample) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 15
[ "Remove", "Absolute", "(", "resample", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "1", "-", "R^2", "transform", "=", "one_minus", "sort_order", "=", "15" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L252-L259
train
slundberg/shap
shap/benchmark/metrics.py
remove_absolute_resample__roc_auc
def remove_absolute_resample__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (resample) xlabel = "Max fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 15 """ return __run_measure(measures.remove_resample, X, y, model_...
python
def remove_absolute_resample__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (resample) xlabel = "Max fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 15 """ return __run_measure(measures.remove_resample, X, y, model_...
[ "def", "remove_absolute_resample__roc_auc", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_resample", ",", "X", ",", "y", ",", "model_generator", ...
Remove Absolute (resample) xlabel = "Max fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 15
[ "Remove", "Absolute", "(", "resample", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "1", "-", "ROC", "AUC", "transform", "=", "one_minus", "sort_order", "=", "15" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L261-L268
train
slundberg/shap
shap/benchmark/metrics.py
keep_negative_impute
def keep_negative_impute(X, y, model_generator, method_name, num_fcounts=11): """ Keep Negative (impute) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 17 """ return __run_measure(measures.keep_impute, X, y, model_generator, m...
python
def keep_negative_impute(X, y, model_generator, method_name, num_fcounts=11): """ Keep Negative (impute) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 17 """ return __run_measure(measures.keep_impute, X, y, model_generator, m...
[ "def", "keep_negative_impute", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_impute", ",", "X", ",", "y", ",", "model_generator", ",", "method_n...
Keep Negative (impute) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 17
[ "Keep", "Negative", "(", "impute", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "Negative", "mean", "model", "output", "transform", "=", "negate", "sort_order", "=", "17" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L279-L286
train
slundberg/shap
shap/benchmark/metrics.py
keep_absolute_impute__r2
def keep_absolute_impute__r2(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (impute) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 18 """ return __run_measure(measures.keep_impute, X, y, model_generator, method_name, 0, nu...
python
def keep_absolute_impute__r2(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (impute) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 18 """ return __run_measure(measures.keep_impute, X, y, model_generator, method_name, 0, nu...
[ "def", "keep_absolute_impute__r2", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_impute", ",", "X", ",", "y", ",", "model_generator", ",", "meth...
Keep Absolute (impute) xlabel = "Max fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 18
[ "Keep", "Absolute", "(", "impute", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "R^2", "transform", "=", "identity", "sort_order", "=", "18" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L288-L295
train
slundberg/shap
shap/benchmark/metrics.py
keep_absolute_impute__roc_auc
def keep_absolute_impute__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (impute) xlabel = "Max fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 19 """ return __run_measure(measures.keep_mask, X, y, model_generator, method_name...
python
def keep_absolute_impute__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Keep Absolute (impute) xlabel = "Max fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 19 """ return __run_measure(measures.keep_mask, X, y, model_generator, method_name...
[ "def", "keep_absolute_impute__roc_auc", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_mask", ",", "X", ",", "y", ",", "model_generator", ",", "m...
Keep Absolute (impute) xlabel = "Max fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 19
[ "Keep", "Absolute", "(", "impute", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "ROC", "AUC", "transform", "=", "identity", "sort_order", "=", "19" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L297-L304
train
slundberg/shap
shap/benchmark/metrics.py
remove_positive_impute
def remove_positive_impute(X, y, model_generator, method_name, num_fcounts=11): """ Remove Positive (impute) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 7 """ return __run_measure(measures.remove_impute, X, y, model_gene...
python
def remove_positive_impute(X, y, model_generator, method_name, num_fcounts=11): """ Remove Positive (impute) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 7 """ return __run_measure(measures.remove_impute, X, y, model_gene...
[ "def", "remove_positive_impute", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_impute", ",", "X", ",", "y", ",", "model_generator", ",", "meth...
Remove Positive (impute) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 7
[ "Remove", "Positive", "(", "impute", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "Negative", "mean", "model", "output", "transform", "=", "negate", "sort_order", "=", "7" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L306-L313
train
slundberg/shap
shap/benchmark/metrics.py
remove_absolute_impute__r2
def remove_absolute_impute__r2(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (impute) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 9 """ return __run_measure(measures.remove_impute, X, y, model_generator, metho...
python
def remove_absolute_impute__r2(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (impute) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 9 """ return __run_measure(measures.remove_impute, X, y, model_generator, metho...
[ "def", "remove_absolute_impute__r2", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_impute", ",", "X", ",", "y", ",", "model_generator", ",", "...
Remove Absolute (impute) xlabel = "Max fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 9
[ "Remove", "Absolute", "(", "impute", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "1", "-", "R^2", "transform", "=", "one_minus", "sort_order", "=", "9" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L324-L331
train
slundberg/shap
shap/benchmark/metrics.py
remove_absolute_impute__roc_auc
def remove_absolute_impute__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (impute) xlabel = "Max fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 9 """ return __run_measure(measures.remove_mask, X, y, model_generator...
python
def remove_absolute_impute__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Remove Absolute (impute) xlabel = "Max fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 9 """ return __run_measure(measures.remove_mask, X, y, model_generator...
[ "def", "remove_absolute_impute__roc_auc", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_mask", ",", "X", ",", "y", ",", "model_generator", ",", ...
Remove Absolute (impute) xlabel = "Max fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 9
[ "Remove", "Absolute", "(", "impute", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "1", "-", "ROC", "AUC", "transform", "=", "one_minus", "sort_order", "=", "9" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L333-L340
train
slundberg/shap
shap/benchmark/metrics.py
keep_negative_retrain
def keep_negative_retrain(X, y, model_generator, method_name, num_fcounts=11): """ Keep Negative (retrain) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 7 """ return __run_measure(measures.keep_retrain, X, y, model_generator,...
python
def keep_negative_retrain(X, y, model_generator, method_name, num_fcounts=11): """ Keep Negative (retrain) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 7 """ return __run_measure(measures.keep_retrain, X, y, model_generator,...
[ "def", "keep_negative_retrain", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "keep_retrain", ",", "X", ",", "y", ",", "model_generator", ",", "method...
Keep Negative (retrain) xlabel = "Max fraction of features kept" ylabel = "Negative mean model output" transform = "negate" sort_order = 7
[ "Keep", "Negative", "(", "retrain", ")", "xlabel", "=", "Max", "fraction", "of", "features", "kept", "ylabel", "=", "Negative", "mean", "model", "output", "transform", "=", "negate", "sort_order", "=", "7" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L351-L358
train
slundberg/shap
shap/benchmark/metrics.py
remove_positive_retrain
def remove_positive_retrain(X, y, model_generator, method_name, num_fcounts=11): """ Remove Positive (retrain) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 11 """ return __run_measure(measures.remove_retrain, X, y, model_...
python
def remove_positive_retrain(X, y, model_generator, method_name, num_fcounts=11): """ Remove Positive (retrain) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 11 """ return __run_measure(measures.remove_retrain, X, y, model_...
[ "def", "remove_positive_retrain", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_measure", "(", "measures", ".", "remove_retrain", ",", "X", ",", "y", ",", "model_generator", ",", "me...
Remove Positive (retrain) xlabel = "Max fraction of features removed" ylabel = "Negative mean model output" transform = "negate" sort_order = 11
[ "Remove", "Positive", "(", "retrain", ")", "xlabel", "=", "Max", "fraction", "of", "features", "removed", "ylabel", "=", "Negative", "mean", "model", "output", "transform", "=", "negate", "sort_order", "=", "11" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L360-L367
train
slundberg/shap
shap/benchmark/metrics.py
batch_remove_absolute_retrain__r2
def batch_remove_absolute_retrain__r2(X, y, model_generator, method_name, num_fcounts=11): """ Batch Remove Absolute (retrain) xlabel = "Fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 13 """ return __run_batch_abs_metric(measures.batch_remove_retrain, X...
python
def batch_remove_absolute_retrain__r2(X, y, model_generator, method_name, num_fcounts=11): """ Batch Remove Absolute (retrain) xlabel = "Fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 13 """ return __run_batch_abs_metric(measures.batch_remove_retrain, X...
[ "def", "batch_remove_absolute_retrain__r2", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_batch_abs_metric", "(", "measures", ".", "batch_remove_retrain", ",", "X", ",", "y", ",", "model...
Batch Remove Absolute (retrain) xlabel = "Fraction of features removed" ylabel = "1 - R^2" transform = "one_minus" sort_order = 13
[ "Batch", "Remove", "Absolute", "(", "retrain", ")", "xlabel", "=", "Fraction", "of", "features", "removed", "ylabel", "=", "1", "-", "R^2", "transform", "=", "one_minus", "sort_order", "=", "13" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L394-L401
train
slundberg/shap
shap/benchmark/metrics.py
batch_keep_absolute_retrain__r2
def batch_keep_absolute_retrain__r2(X, y, model_generator, method_name, num_fcounts=11): """ Batch Keep Absolute (retrain) xlabel = "Fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 13 """ return __run_batch_abs_metric(measures.batch_keep_retrain, X, y, model_gen...
python
def batch_keep_absolute_retrain__r2(X, y, model_generator, method_name, num_fcounts=11): """ Batch Keep Absolute (retrain) xlabel = "Fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 13 """ return __run_batch_abs_metric(measures.batch_keep_retrain, X, y, model_gen...
[ "def", "batch_keep_absolute_retrain__r2", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_batch_abs_metric", "(", "measures", ".", "batch_keep_retrain", ",", "X", ",", "y", ",", "model_gen...
Batch Keep Absolute (retrain) xlabel = "Fraction of features kept" ylabel = "R^2" transform = "identity" sort_order = 13
[ "Batch", "Keep", "Absolute", "(", "retrain", ")", "xlabel", "=", "Fraction", "of", "features", "kept", "ylabel", "=", "R^2", "transform", "=", "identity", "sort_order", "=", "13" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L403-L410
train
slundberg/shap
shap/benchmark/metrics.py
batch_remove_absolute_retrain__roc_auc
def batch_remove_absolute_retrain__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Batch Remove Absolute (retrain) xlabel = "Fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 13 """ return __run_batch_abs_metric(measures.batch_remove_r...
python
def batch_remove_absolute_retrain__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Batch Remove Absolute (retrain) xlabel = "Fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 13 """ return __run_batch_abs_metric(measures.batch_remove_r...
[ "def", "batch_remove_absolute_retrain__roc_auc", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_batch_abs_metric", "(", "measures", ".", "batch_remove_retrain", ",", "X", ",", "y", ",", "...
Batch Remove Absolute (retrain) xlabel = "Fraction of features removed" ylabel = "1 - ROC AUC" transform = "one_minus" sort_order = 13
[ "Batch", "Remove", "Absolute", "(", "retrain", ")", "xlabel", "=", "Fraction", "of", "features", "removed", "ylabel", "=", "1", "-", "ROC", "AUC", "transform", "=", "one_minus", "sort_order", "=", "13" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L412-L419
train
slundberg/shap
shap/benchmark/metrics.py
batch_keep_absolute_retrain__roc_auc
def batch_keep_absolute_retrain__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Batch Keep Absolute (retrain) xlabel = "Fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 13 """ return __run_batch_abs_metric(measures.batch_keep_retrain, X, y, ...
python
def batch_keep_absolute_retrain__roc_auc(X, y, model_generator, method_name, num_fcounts=11): """ Batch Keep Absolute (retrain) xlabel = "Fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 13 """ return __run_batch_abs_metric(measures.batch_keep_retrain, X, y, ...
[ "def", "batch_keep_absolute_retrain__roc_auc", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ",", "num_fcounts", "=", "11", ")", ":", "return", "__run_batch_abs_metric", "(", "measures", ".", "batch_keep_retrain", ",", "X", ",", "y", ",", "mode...
Batch Keep Absolute (retrain) xlabel = "Fraction of features kept" ylabel = "ROC AUC" transform = "identity" sort_order = 13
[ "Batch", "Keep", "Absolute", "(", "retrain", ")", "xlabel", "=", "Fraction", "of", "features", "kept", "ylabel", "=", "ROC", "AUC", "transform", "=", "identity", "sort_order", "=", "13" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L421-L428
train
slundberg/shap
shap/benchmark/metrics.py
__score_method
def __score_method(X, y, fcounts, model_generator, score_function, method_name, nreps=10, test_size=100, cache_dir="/tmp"): """ Test an explanation method. """ old_seed = np.random.seed() np.random.seed(3293) # average the method scores over several train/test splits method_reps = [] data...
python
def __score_method(X, y, fcounts, model_generator, score_function, method_name, nreps=10, test_size=100, cache_dir="/tmp"): """ Test an explanation method. """ old_seed = np.random.seed() np.random.seed(3293) # average the method scores over several train/test splits method_reps = [] data...
[ "def", "__score_method", "(", "X", ",", "y", ",", "fcounts", ",", "model_generator", ",", "score_function", ",", "method_name", ",", "nreps", "=", "10", ",", "test_size", "=", "100", ",", "cache_dir", "=", "\"/tmp\"", ")", ":", "old_seed", "=", "np", "."...
Test an explanation method.
[ "Test", "an", "explanation", "method", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L446-L495
train
slundberg/shap
shap/benchmark/metrics.py
human_and_00
def human_and_00(X, y, model_generator, method_name): """ AND (false/false) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function ...
python
def human_and_00(X, y, model_generator, method_name): """ AND (false/false) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function ...
[ "def", "human_and_00", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_and", "(", "X", ",", "model_generator", ",", "method_name", ",", "False", ",", "False", ")" ]
AND (false/false) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points ...
[ "AND", "(", "false", "/", "false", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L578-L592
train
slundberg/shap
shap/benchmark/metrics.py
human_and_01
def human_and_01(X, y, model_generator, method_name): """ AND (false/true) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function ...
python
def human_and_01(X, y, model_generator, method_name): """ AND (false/true) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function ...
[ "def", "human_and_01", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_and", "(", "X", ",", "model_generator", ",", "method_name", ",", "False", ",", "True", ")" ]
AND (false/true) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points i...
[ "AND", "(", "false", "/", "true", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L594-L608
train
slundberg/shap
shap/benchmark/metrics.py
human_and_11
def human_and_11(X, y, model_generator, method_name): """ AND (true/true) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function ...
python
def human_and_11(X, y, model_generator, method_name): """ AND (true/true) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function ...
[ "def", "human_and_11", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_and", "(", "X", ",", "model_generator", ",", "method_name", ",", "True", ",", "True", ")" ]
AND (true/true) This tests how well a feature attribution method agrees with human intuition for an AND operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points if...
[ "AND", "(", "true", "/", "true", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L610-L624
train
slundberg/shap
shap/benchmark/metrics.py
human_or_00
def human_or_00(X, y, model_generator, method_name): """ OR (false/false) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function w...
python
def human_or_00(X, y, model_generator, method_name): """ OR (false/false) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function w...
[ "def", "human_or_00", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_or", "(", "X", ",", "model_generator", ",", "method_name", ",", "False", ",", "False", ")" ]
OR (false/false) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points if...
[ "OR", "(", "false", "/", "false", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L649-L663
train
slundberg/shap
shap/benchmark/metrics.py
human_or_01
def human_or_01(X, y, model_generator, method_name): """ OR (false/true) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function wh...
python
def human_or_01(X, y, model_generator, method_name): """ OR (false/true) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function wh...
[ "def", "human_or_01", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_or", "(", "X", ",", "model_generator", ",", "method_name", ",", "False", ",", "True", ")" ]
OR (false/true) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points if ...
[ "OR", "(", "false", "/", "true", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L665-L679
train
slundberg/shap
shap/benchmark/metrics.py
human_or_11
def human_or_11(X, y, model_generator, method_name): """ OR (true/true) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function whe...
python
def human_or_11(X, y, model_generator, method_name): """ OR (true/true) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function whe...
[ "def", "human_or_11", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_or", "(", "X", ",", "model_generator", ",", "method_name", ",", "True", ",", "True", ")" ]
OR (true/true) This tests how well a feature attribution method agrees with human intuition for an OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points if c...
[ "OR", "(", "true", "/", "true", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L681-L695
train
slundberg/shap
shap/benchmark/metrics.py
human_xor_00
def human_xor_00(X, y, model_generator, method_name): """ XOR (false/false) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following fu...
python
def human_xor_00(X, y, model_generator, method_name): """ XOR (false/false) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following fu...
[ "def", "human_xor_00", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_xor", "(", "X", ",", "model_generator", ",", "method_name", ",", "False", ",", "False", ")" ]
XOR (false/false) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 po...
[ "XOR", "(", "false", "/", "false", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L720-L734
train
slundberg/shap
shap/benchmark/metrics.py
human_xor_01
def human_xor_01(X, y, model_generator, method_name): """ XOR (false/true) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following fun...
python
def human_xor_01(X, y, model_generator, method_name): """ XOR (false/true) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following fun...
[ "def", "human_xor_01", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_xor", "(", "X", ",", "model_generator", ",", "method_name", ",", "False", ",", "True", ")" ]
XOR (false/true) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 poi...
[ "XOR", "(", "false", "/", "true", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L736-L750
train
slundberg/shap
shap/benchmark/metrics.py
human_xor_11
def human_xor_11(X, y, model_generator, method_name): """ XOR (true/true) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following func...
python
def human_xor_11(X, y, model_generator, method_name): """ XOR (true/true) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following func...
[ "def", "human_xor_11", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_xor", "(", "X", ",", "model_generator", ",", "method_name", ",", "True", ",", "True", ")" ]
XOR (true/true) This tests how well a feature attribution method agrees with human intuition for an eXclusive OR operation combined with linear effects. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 poin...
[ "XOR", "(", "true", "/", "true", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L752-L766
train
slundberg/shap
shap/benchmark/metrics.py
human_sum_00
def human_sum_00(X, y, model_generator, method_name): """ SUM (false/false) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are tr...
python
def human_sum_00(X, y, model_generator, method_name): """ SUM (false/false) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are tr...
[ "def", "human_sum_00", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_sum", "(", "X", ",", "model_generator", ",", "method_name", ",", "False", ",", "False", ")" ]
SUM (false/false) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points if cough: +2 points trans...
[ "SUM", "(", "false", "/", "false", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L791-L804
train
slundberg/shap
shap/benchmark/metrics.py
human_sum_01
def human_sum_01(X, y, model_generator, method_name): """ SUM (false/true) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are tru...
python
def human_sum_01(X, y, model_generator, method_name): """ SUM (false/true) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are tru...
[ "def", "human_sum_01", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_sum", "(", "X", ",", "model_generator", ",", "method_name", ",", "False", ",", "True", ")" ]
SUM (false/true) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points if cough: +2 points transf...
[ "SUM", "(", "false", "/", "true", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L806-L819
train
slundberg/shap
shap/benchmark/metrics.py
human_sum_11
def human_sum_11(X, y, model_generator, method_name): """ SUM (true/true) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true...
python
def human_sum_11(X, y, model_generator, method_name): """ SUM (true/true) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true...
[ "def", "human_sum_11", "(", "X", ",", "y", ",", "model_generator", ",", "method_name", ")", ":", "return", "_human_sum", "(", "X", ",", "model_generator", ",", "method_name", ",", "True", ",", "True", ")" ]
SUM (true/true) This tests how well a feature attribution method agrees with human intuition for a SUM operation. This metric deals specifically with the question of credit allocation for the following function when all three inputs are true: if fever: +2 points if cough: +2 points transfo...
[ "SUM", "(", "true", "/", "true", ")" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/metrics.py#L821-L834
train
slundberg/shap
shap/explainers/linear.py
LinearExplainer._estimate_transforms
def _estimate_transforms(self, nsamples): """ Uses block matrix inversion identities to quickly estimate transforms. After a bit of matrix math we can isolate a transform matrix (# features x # features) that is independent of any sample we are explaining. It is the result of averaging over ...
python
def _estimate_transforms(self, nsamples): """ Uses block matrix inversion identities to quickly estimate transforms. After a bit of matrix math we can isolate a transform matrix (# features x # features) that is independent of any sample we are explaining. It is the result of averaging over ...
[ "def", "_estimate_transforms", "(", "self", ",", "nsamples", ")", ":", "M", "=", "len", "(", "self", ".", "coef", ")", "mean_transform", "=", "np", ".", "zeros", "(", "(", "M", ",", "M", ")", ")", "x_transform", "=", "np", ".", "zeros", "(", "(", ...
Uses block matrix inversion identities to quickly estimate transforms. After a bit of matrix math we can isolate a transform matrix (# features x # features) that is independent of any sample we are explaining. It is the result of averaging over all feature permutations, but we just use a fixed...
[ "Uses", "block", "matrix", "inversion", "identities", "to", "quickly", "estimate", "transforms", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/linear.py#L113-L175
train
slundberg/shap
shap/explainers/linear.py
LinearExplainer.shap_values
def shap_values(self, X): """ Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame A matrix of samples (# samples x # features) on which to explain the model's output. Returns ------- For models wit...
python
def shap_values(self, X): """ Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame A matrix of samples (# samples x # features) on which to explain the model's output. Returns ------- For models wit...
[ "def", "shap_values", "(", "self", ",", "X", ")", ":", "# convert dataframes", "if", "str", "(", "type", "(", "X", ")", ")", ".", "endswith", "(", "\"pandas.core.series.Series'>\"", ")", ":", "X", "=", "X", ".", "values", "elif", "str", "(", "type", "(...
Estimate the SHAP values for a set of samples. Parameters ---------- X : numpy.array or pandas.DataFrame A matrix of samples (# samples x # features) on which to explain the model's output. Returns ------- For models with a single output this returns a matri...
[ "Estimate", "the", "SHAP", "values", "for", "a", "set", "of", "samples", "." ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/explainers/linear.py#L177-L215
train
slundberg/shap
shap/benchmark/models.py
independentlinear60__ffnn
def independentlinear60__ffnn(): """ 4-Layer Neural Network """ from keras.models import Sequential from keras.layers import Dense model = Sequential() model.add(Dense(32, activation='relu', input_dim=60)) model.add(Dense(20, activation='relu')) model.add(Dense(20, activation='relu')) ...
python
def independentlinear60__ffnn(): """ 4-Layer Neural Network """ from keras.models import Sequential from keras.layers import Dense model = Sequential() model.add(Dense(32, activation='relu', input_dim=60)) model.add(Dense(20, activation='relu')) model.add(Dense(20, activation='relu')) ...
[ "def", "independentlinear60__ffnn", "(", ")", ":", "from", "keras", ".", "models", "import", "Sequential", "from", "keras", ".", "layers", "import", "Dense", "model", "=", "Sequential", "(", ")", "model", ".", "add", "(", "Dense", "(", "32", ",", "activati...
4-Layer Neural Network
[ "4", "-", "Layer", "Neural", "Network" ]
b280cb81d498b9d98565cad8dd16fc88ae52649f
https://github.com/slundberg/shap/blob/b280cb81d498b9d98565cad8dd16fc88ae52649f/shap/benchmark/models.py#L114-L130
train