id int64 0 328k | repository_name stringlengths 7 58 | file_path stringlengths 9 302 | class_name stringlengths 5 256 | human_written_code stringlengths 16 2.16M | class_skeleton stringlengths 18 1.49M ⌀ | total_program_units int64 1 1.76k | total_doc_str int64 0 771 | AvgCountLine float64 0 7.89k | AvgCountLineBlank float64 0 297 | AvgCountLineCode float64 0 7.89k | AvgCountLineComment float64 0 7.89k | AvgCyclomatic float64 0 130 | CommentToCodeRatio float64 0 168 | CountClassBase float64 0 40 | CountClassCoupled float64 0 583 | CountClassCoupledModified float64 0 575 | CountClassDerived float64 0 5.35k | CountDeclInstanceMethod float64 0 529 | CountDeclInstanceVariable float64 0 296 | CountDeclMethod float64 0 599 | CountDeclMethodAll float64 0 1.12k | CountLine float64 1 40.4k | CountLineBlank float64 0 8.16k | CountLineCode float64 1 25.7k | CountLineCodeDecl float64 1 8.15k | CountLineCodeExe float64 0 24.2k | CountLineComment float64 0 16.5k | CountStmt float64 1 9.71k | CountStmtDecl float64 1 8.15k | CountStmtExe float64 0 9.69k | MaxCyclomatic float64 0 759 | MaxInheritanceTree float64 0 16 | MaxNesting float64 0 34 | SumCyclomatic float64 0 2.9k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
15,300 | slundberg/shap | slundberg_shap/shap/_explanation.py | shap._explanation.OpHistoryItem | from typing import Any, Callable, cast
from dataclasses import dataclass, field
@dataclass
class OpHistoryItem:
"""An operation that has been applied to an Explanation object."""
name: str
prev_shape: tuple[int, ...]
args: tuple[Any, ...] = ()
kwargs: dict[str, Any] = field(default_factory=dict)
... | @dataclass
class OpHistoryItem:
'''An operation that has been applied to an Explanation object.'''
pass | 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0.17 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 1 | 6 | 4 | 5 | 1 | 6 | 4 | 5 | 0 | 0 | 0 | 0 |
15,301 | slundberg/shap | slundberg_shap/shap/_serializable.py | shap._serializable.Deserializer | import cloudpickle
import pickle
import numpy as np
class Deserializer:
"""Load data items from an input stream."""
def __init__(self, in_stream, block_name, min_version, max_version):
self.in_stream = in_stream
self.block_name = block_name
self.block_min_version = min_version
... |
class Deserializer:
'''Load data items from an input stream.'''
def __init__(self, in_stream, block_name, min_version, max_version):
pass
def __enter__(self):
pass
def __exit__(self, exception_type, exception_value, traceback):
pass
def load(self, name, decoder=None):
... | 6 | 2 | 18 | 1 | 15 | 2 | 4 | 0.12 | 0 | 4 | 1 | 0 | 5 | 6 | 5 | 5 | 96 | 10 | 78 | 20 | 72 | 9 | 60 | 20 | 54 | 7 | 0 | 2 | 19 |
15,302 | slundberg/shap | slundberg_shap/shap/_serializable.py | shap._serializable.Serializable | import inspect
import pickle
class Serializable:
"""This is the superclass of all serializable objects."""
def save(self, out_file):
"""Save the model to the given file stream."""
pickle.dump(type(self), out_file)
@classmethod
def load(cls, in_file, instantiate=True):
"""This ... |
class Serializable:
'''This is the superclass of all serializable objects.'''
def save(self, out_file):
'''Save the model to the given file stream.'''
pass
@classmethod
def load(cls, in_file, instantiate=True):
'''This is meant to be overridden by subclasses and called with sup... | 6 | 4 | 9 | 1 | 5 | 3 | 2 | 0.56 | 0 | 2 | 0 | 3 | 1 | 0 | 3 | 3 | 35 | 7 | 18 | 9 | 12 | 10 | 16 | 7 | 12 | 3 | 0 | 1 | 6 |
15,303 | slundberg/shap | slundberg_shap/shap/_serializable.py | shap._serializable.Serializer | import cloudpickle
import pickle
class Serializer:
"""Save data items to an input stream."""
def __init__(self, out_stream, block_name, version):
self.out_stream = out_stream
self.block_name = block_name
self.block_version = version
self.serializer_version = 0
def __enter_... |
class Serializer:
'''Save data items to an input stream.'''
def __init__(self, out_stream, block_name, version):
pass
def __enter__(self):
pass
def __exit__(self, exception_type, exception_value, traceback):
pass
def save(self, name, value, encoder='auto'):
'''Du... | 5 | 2 | 12 | 0 | 11 | 1 | 3 | 0.09 | 0 | 5 | 1 | 0 | 4 | 4 | 4 | 4 | 52 | 4 | 46 | 9 | 41 | 4 | 40 | 9 | 35 | 7 | 0 | 2 | 10 |
15,304 | slundberg/shap | slundberg_shap/shap/actions/_action.py | shap.actions._action.Action | class Action:
"""Abstract action class."""
def __init__(self, cost):
self.cost = cost
self._group_index = 0
self._grouped_index = 0
def __call__(self, *args):
raise NotImplementedError
def __lt__(self, other_action):
return self.cost < other_action.cost
de... | class Action:
'''Abstract action class.'''
def __init__(self, cost):
pass
def __call__(self, *args):
pass
def __lt__(self, other_action):
pass
def __repr__(self):
pass | 5 | 1 | 3 | 0 | 3 | 0 | 1 | 0.09 | 0 | 1 | 0 | 4 | 4 | 3 | 4 | 4 | 16 | 4 | 11 | 8 | 6 | 1 | 11 | 8 | 6 | 1 | 0 | 0 | 4 |
15,305 | slundberg/shap | slundberg_shap/shap/actions/_optimizer.py | shap.actions._optimizer.ActionOptimizer | from ..utils._exceptions import ConvergenceError, InvalidAction
import queue
import copy
from ._action import Action
import warnings
class ActionOptimizer:
def __init__(self, model, actions: list[Action | list[Action]]):
self.model = model
warnings.warn('Note that ActionOptimizer is still in an al... |
class ActionOptimizer:
def __init__(self, model, actions: list[Action | list[Action]]):
pass
def __call__(self, *args, max_evals=10000):
pass | 3 | 0 | 37 | 4 | 27 | 7 | 9 | 0.24 | 0 | 9 | 3 | 0 | 2 | 2 | 2 | 2 | 76 | 9 | 54 | 19 | 51 | 13 | 47 | 19 | 44 | 12 | 0 | 5 | 17 |
15,306 | slundberg/shap | slundberg_shap/shap/benchmark/_compute.py | shap.benchmark._compute.ComputeTime | from ._result import BenchmarkResult
class ComputeTime:
"""Extracts a runtime benchmark result from the passed Explanation."""
def __call__(self, explanation, name):
return BenchmarkResult('compute time', name, value=explanation.compute_time / explanation.shape[0]) |
class ComputeTime:
'''Extracts a runtime benchmark result from the passed Explanation.'''
def __call__(self, explanation, name):
pass | 2 | 1 | 2 | 0 | 2 | 0 | 1 | 0.33 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 5 | 1 | 3 | 2 | 1 | 1 | 3 | 2 | 1 | 1 | 0 | 0 | 1 |
15,307 | slundberg/shap | slundberg_shap/shap/benchmark/_explanation_error.py | shap.benchmark._explanation_error.ExplanationError | from shap.utils._exceptions import DimensionError
import numpy as np
from ._result import BenchmarkResult
from shap import Explanation, links
from shap.utils import MaskedModel, partition_tree_shuffle
from shap.maskers import FixedComposite, Image, Text
from tqdm.auto import tqdm
import time
class ExplanationError:
... |
class ExplanationError:
'''A measure of the explanation error relative to a model's actual output.
This benchmark metric measures the discrepancy between the output of the model predicted by an
attribution explanation vs. the actual output of the model. This discrepancy is measured over
many masking pa... | 3 | 3 | 81 | 14 | 52 | 16 | 11 | 0.41 | 0 | 14 | 7 | 0 | 2 | 9 | 2 | 2 | 178 | 31 | 104 | 47 | 91 | 43 | 80 | 37 | 77 | 18 | 0 | 3 | 22 |
15,308 | slundberg/shap | slundberg_shap/shap/benchmark/_result.py | shap.benchmark._result.BenchmarkResult | import numpy as np
import sklearn
class BenchmarkResult:
"""The result of a benchmark run."""
def __init__(self, metric, method, value=None, curve_x=None, curve_y=None, curve_y_std=None, value_sign=None):
self.metric = metric
self.method = method
self.value = value
self.curve_x... |
class BenchmarkResult:
'''The result of a benchmark run.'''
def __init__(self, metric, method, value=None, curve_x=None, curve_y=None, curve_y_std=None, value_sign=None):
pass
@property
def full_name(self):
pass | 4 | 1 | 7 | 0 | 7 | 0 | 2 | 0.06 | 0 | 0 | 0 | 0 | 2 | 7 | 2 | 2 | 19 | 2 | 16 | 11 | 12 | 1 | 15 | 10 | 12 | 3 | 0 | 1 | 4 |
15,309 | slundberg/shap | slundberg_shap/shap/benchmark/_sequential.py | shap.benchmark._sequential.SequentialMasker | import pandas as pd
class SequentialMasker:
def __init__(self, mask_type, sort_order, masker, model, *model_args, batch_size=500):
for arg in model_args:
if isinstance(arg, pd.DataFrame):
raise TypeError('DataFrame arguments dont iterate correctly, pass numpy arrays instead!')
... |
class SequentialMasker:
def __init__(self, mask_type, sort_order, masker, model, *model_args, batch_size=500):
pass
def __call__(self, explanation, name, **kwargs):
pass | 3 | 0 | 18 | 2 | 5 | 12 | 2 | 2.3 | 0 | 2 | 1 | 0 | 2 | 3 | 2 | 2 | 37 | 4 | 10 | 7 | 7 | 23 | 10 | 7 | 7 | 3 | 0 | 2 | 4 |
15,310 | slundberg/shap | slundberg_shap/shap/benchmark/_sequential.py | shap.benchmark._sequential.SequentialPerturbation | from shap import Explanation, links
from shap.maskers import FixedComposite, Image, Text
from ._result import BenchmarkResult
import pandas as pd
import numpy as np
import time
from tqdm.auto import tqdm
import sklearn
import matplotlib.pyplot as pl
from shap.utils import MaskedModel
class SequentialPerturbation:
... |
class SequentialPerturbation:
def __init__(self, model, masker, sort_order, perturbation, linearize_link=False):
pass
def __call__(self, name, explanation, *model_args, percent=0.01, indices=[], y=None, label=None, silent=False, debug_mode=False, batch_size=10):
pass
def score(self, expl... | 5 | 1 | 73 | 12 | 53 | 8 | 13 | 0.15 | 0 | 13 | 6 | 0 | 4 | 11 | 4 | 4 | 294 | 51 | 211 | 91 | 194 | 32 | 173 | 79 | 168 | 25 | 0 | 6 | 50 |
15,311 | slundberg/shap | slundberg_shap/shap/benchmark/models.py | shap.benchmark.models.KerasWrap | from sklearn.preprocessing import StandardScaler
class KerasWrap:
"""A wrapper that allows us to set parameters in the constructor and do a reset before fitting."""
def __init__(self, model, epochs, flatten_output=False):
self.model = model
self.epochs = epochs
self.flatten_output = fl... |
class KerasWrap:
'''A wrapper that allows us to set parameters in the constructor and do a reset before fitting.'''
def __init__(self, model, epochs, flatten_output=False):
pass
def fit(self, X, y, verbose=0):
pass
def predict(self, X):
pass | 4 | 1 | 6 | 0 | 6 | 0 | 2 | 0.05 | 0 | 1 | 0 | 0 | 3 | 5 | 3 | 3 | 24 | 3 | 20 | 9 | 16 | 1 | 18 | 9 | 14 | 2 | 0 | 1 | 5 |
15,312 | slundberg/shap | slundberg_shap/shap/explainers/_additive.py | shap.explainers._additive.AdditiveExplainer | from ..utils import MaskedModel, safe_isinstance
from ._explainer import Explainer
import numpy as np
class AdditiveExplainer(Explainer):
"""Computes SHAP values for generalized additive models.
This assumes that the model only has first-order effects. Extending this to
second- and third-order effects is ... |
class AdditiveExplainer(Explainer):
'''Computes SHAP values for generalized additive models.
This assumes that the model only has first-order effects. Extending this to
second- and third-order effects is future work (if you apply this to those models right now
you will get incorrect answers that fail a... | 6 | 5 | 22 | 3 | 11 | 8 | 3 | 0.76 | 1 | 5 | 1 | 0 | 3 | 4 | 4 | 13 | 99 | 18 | 46 | 18 | 40 | 35 | 35 | 17 | 30 | 5 | 2 | 2 | 11 |
15,313 | slundberg/shap | slundberg_shap/shap/explainers/_deep/__init__.py | shap.explainers._deep.DeepExplainer | from ..._explanation import Explanation
from .._explainer import Explainer
class DeepExplainer(Explainer):
"""Meant to approximate SHAP values for deep learning models.
This is an enhanced version of the DeepLIFT algorithm (Deep SHAP) where, similar to Kernel SHAP, we
approximate the conditional expectati... |
class DeepExplainer(Explainer):
'''Meant to approximate SHAP values for deep learning models.
This is an enhanced version of the DeepLIFT algorithm (Deep SHAP) where, similar to Kernel SHAP, we
approximate the conditional expectations of SHAP values using a selection of background samples.
Lundberg and... | 4 | 4 | 46 | 8 | 10 | 29 | 3 | 3.19 | 1 | 8 | 3 | 0 | 3 | 2 | 3 | 12 | 158 | 30 | 31 | 12 | 25 | 99 | 29 | 12 | 23 | 6 | 2 | 2 | 8 |
15,314 | slundberg/shap | slundberg_shap/shap/explainers/_deep/deep_pytorch.py | shap.explainers._deep.deep_pytorch.PyTorchDeep | import warnings
from packaging import version
from .deep_utils import _check_additivity
import numpy as np
from .._explainer import Explainer
class PyTorchDeep(Explainer):
def __init__(self, model, data):
import torch
if version.parse(torch.__version__) < version.parse('0.4'):
warnings... |
class PyTorchDeep(Explainer):
def __init__(self, model, data):
pass
def add_target_handle(self, layer):
pass
def add_handles(self, model, forward_handle, backward_handle):
'''Add handles to all non-container layers in the model.
Recursively for non-container layers
... | 7 | 2 | 37 | 3 | 31 | 4 | 8 | 0.14 | 1 | 8 | 0 | 0 | 6 | 12 | 6 | 15 | 229 | 20 | 185 | 55 | 175 | 26 | 152 | 55 | 142 | 24 | 2 | 4 | 48 |
15,315 | slundberg/shap | slundberg_shap/shap/explainers/_deep/deep_tf.py | shap.explainers._deep.deep_tf.TFDeep | from ..tf_utils import _get_graph, _get_model_inputs, _get_model_output, _get_session
from tensorflow.python.eager import execute as tf_execute
from tensorflow.python.eager import backprop as tf_backprop
from ...utils._exceptions import DimensionError
from .._explainer import Explainer
import numpy as np
from tensorflo... |
class TFDeep(Explainer):
'''Using tf.gradients to implement the backpropagation was
inspired by the gradient-based implementation approach proposed by Ancona et al, ICLR 2018. Note
that this package does not currently use the reveal-cancel rule for ReLu units proposed in DeepLIFT.
'''
def __init__... | 16 | 6 | 32 | 4 | 23 | 6 | 7 | 0.3 | 1 | 11 | 1 | 0 | 9 | 17 | 9 | 18 | 389 | 55 | 261 | 86 | 244 | 77 | 224 | 81 | 209 | 23 | 2 | 4 | 85 |
15,316 | slundberg/shap | slundberg_shap/shap/explainers/_exact.py | shap.explainers._exact.ExactExplainer | import numpy as np
from ..models import Model
from ._explainer import Explainer
from ..utils import MaskedModel, delta_minimization_order, make_masks, shapley_coefficients
from .. import links
class ExactExplainer(Explainer):
"""Computes SHAP values via an optimized exact enumeration.
This works well for stan... |
class ExactExplainer(Explainer):
'''Computes SHAP values via an optimized exact enumeration.
This works well for standard Shapley value maskers for models with less than ~15 features that vary
from the background per sample. It also works well for Owen values from hclustering structured
maskers when th... | 5 | 4 | 41 | 6 | 23 | 13 | 5 | 0.65 | 1 | 8 | 2 | 0 | 4 | 5 | 4 | 13 | 179 | 27 | 93 | 29 | 79 | 60 | 56 | 20 | 51 | 15 | 2 | 3 | 20 |
15,317 | slundberg/shap | slundberg_shap/shap/explainers/_explainer.py | shap.explainers._explainer.Explainer | from ..utils._exceptions import InvalidAlgorithmError
import copy
import numpy as np
from .. import explainers, links, maskers, models
from .._explanation import Explanation
from ..utils.transformers import is_transformers_lm
import pandas as pd
from .._serializable import Deserializer, Serializable, Serializer
import ... | null | 9 | 7 | 83 | 6 | 60 | 17 | 12 | 0.29 | 1 | 33 | 22 | 19 | 4 | 7 | 6 | 9 | 511 | 45 | 364 | 66 | 334 | 105 | 182 | 41 | 175 | 33 | 1 | 5 | 71 |
15,318 | slundberg/shap | slundberg_shap/shap/explainers/_gpu_tree.py | shap.explainers._gpu_tree.GPUTreeExplainer | import numpy as np
from ._tree import TreeExplainer, _xgboost_cat_unsupported, feature_perturbation_codes, output_transform_codes
from ..utils import assert_import, record_import_error
class GPUTreeExplainer(TreeExplainer):
"""Experimental GPU accelerated version of TreeExplainer. Currently requires source build w... |
class GPUTreeExplainer(TreeExplainer):
'''Experimental GPU accelerated version of TreeExplainer. Currently requires source build with
cuda available and 'CUDA_PATH' environment variable defined.
Examples
--------
See `GPUTree explainer examples <https://shap.readthedocs.io/en/latest/api_examples/ex... | 3 | 3 | 75 | 10 | 35 | 31 | 3 | 0.96 | 1 | 1 | 0 | 0 | 2 | 0 | 2 | 21 | 160 | 23 | 70 | 11 | 67 | 67 | 25 | 11 | 22 | 3 | 3 | 1 | 5 |
15,319 | slundberg/shap | slundberg_shap/shap/explainers/_gradient.py | shap.explainers._gradient.GradientExplainer | import pandas as pd
from .._explanation import Explanation
from ..explainers._explainer import Explainer
class GradientExplainer(Explainer):
"""Explains a model using expected gradients (an extension of integrated gradients).
Expected gradients an extension of the integrated gradients method (Sundararajan et ... | null | 4 | 4 | 40 | 7 | 10 | 24 | 3 | 2.83 | 1 | 6 | 3 | 0 | 3 | 2 | 3 | 12 | 141 | 26 | 30 | 11 | 24 | 85 | 25 | 9 | 21 | 7 | 2 | 2 | 9 |
15,320 | slundberg/shap | slundberg_shap/shap/explainers/_gradient.py | shap.explainers._gradient._PyTorchGradient | import numpy as np
from ..explainers._explainer import Explainer
from packaging import version
import warnings
class _PyTorchGradient(Explainer):
def __init__(self, model, data, batch_size=50, local_smoothing=0):
import torch
if version.parse(torch.__version__) < version.parse('0.4'):
... |
class _PyTorchGradient(Explainer):
def __init__(self, model, data, batch_size=50, local_smoothing=0):
pass
def gradient(self, idx, inputs):
pass
@staticmethod
def get_interim_input(self, input, output):
pass
def add_handles(self, layer):
pass
def shap_values(... | 7 | 0 | 44 | 4 | 34 | 6 | 9 | 0.18 | 1 | 7 | 0 | 0 | 4 | 12 | 5 | 14 | 227 | 23 | 174 | 59 | 162 | 32 | 139 | 55 | 130 | 29 | 2 | 8 | 44 |
15,321 | slundberg/shap | slundberg_shap/shap/explainers/_gradient.py | shap.explainers._gradient._TFGradient | import pandas as pd
import numpy as np
from ..explainers._explainer import Explainer
from ..explainers.tf_utils import _get_graph, _get_model_inputs, _get_model_output, _get_session
from packaging import version
import warnings
class _TFGradient(Explainer):
def __init__(self, model, data, session=None, batch_size... |
class _TFGradient(Explainer):
def __init__(self, model, data, session=None, batch_size=50, local_smoothing=0):
pass
def gradient(self, i):
pass
@tf.function
def grad_graph(x):
pass
@tf.function... | 9 | 0 | 46 | 6 | 33 | 7 | 9 | 0.23 | 1 | 7 | 0 | 0 | 4 | 13 | 4 | 13 | 255 | 35 | 181 | 69 | 161 | 41 | 160 | 62 | 144 | 25 | 2 | 5 | 54 |
15,322 | slundberg/shap | slundberg_shap/shap/explainers/_kernel.py | shap.explainers._kernel.KernelExplainer | import gc
import pandas as pd
from ..utils._exceptions import DimensionError
from scipy.special import binom
from ._explainer import Explainer
from tqdm.auto import tqdm
import copy
import scipy.sparse
from _kernel_lib import _exp_val
from ..utils import safe_isinstance
from packaging import version
import sklearn
impo... |
class KernelExplainer(Explainer):
'''Uses the Kernel SHAP method to explain the output of any function.
Kernel SHAP is a method that uses a special weighted linear regression
to compute the importance of each feature. The computed importance values
are Shapley values from game theory and also coefficie... | 14 | 2 | 58 | 6 | 41 | 11 | 9 | 0.35 | 1 | 20 | 4 | 1 | 9 | 29 | 11 | 20 | 698 | 87 | 454 | 155 | 439 | 160 | 394 | 152 | 381 | 28 | 2 | 5 | 104 |
15,323 | slundberg/shap | slundberg_shap/shap/explainers/_linear.py | shap.explainers._linear.LinearExplainer | from ._explainer import Explainer
import warnings
from .. import links, maskers
import numpy as np
from ..utils._exceptions import DimensionError, InvalidFeaturePerturbationError, InvalidModelError
from tqdm.auto import tqdm
from scipy.sparse import issparse
import pandas as pd
class LinearExplainer(Explainer):
""... | null | 9 | 6 | 58 | 9 | 38 | 12 | 10 | 0.55 | 1 | 19 | 6 | 0 | 4 | 12 | 6 | 15 | 428 | 74 | 230 | 49 | 221 | 126 | 175 | 47 | 168 | 28 | 2 | 3 | 57 |
15,324 | slundberg/shap | slundberg_shap/shap/explainers/_partition.py | shap.explainers._partition.PartitionExplainer | from ._explainer import Explainer
import queue
import numpy as np
from .. import Explanation, links
import time
from ..models import Model
from ..utils import MaskedModel, OpChain, make_masks, safe_isinstance
from tqdm.auto import tqdm
class PartitionExplainer(Explainer):
"""Uses the Partition SHAP method to expla... |
class PartitionExplainer(Explainer):
'''Uses the Partition SHAP method to explain the output of any function.
Partition SHAP computes Shapley values recursively through a hierarchy of features, this
hierarchy defines feature coalitions and results in the Owen values from game theory.
The PartitionExpla... | 9 | 6 | 75 | 11 | 46 | 20 | 10 | 0.51 | 1 | 11 | 5 | 0 | 6 | 11 | 6 | 15 | 534 | 84 | 305 | 108 | 264 | 156 | 211 | 76 | 202 | 25 | 2 | 4 | 68 |
15,325 | slundberg/shap | slundberg_shap/shap/explainers/_partition.py | shap.explainers._partition.PartitionExplainer.__init__.PartitionExplainer | from tqdm.auto import tqdm
from .. import Explanation, links
from ..utils import MaskedModel, OpChain, make_masks, safe_isinstance
from ._explainer import Explainer
import queue
import time
import numpy as np
from ..models import Model
class PartitionExplainer(Explainer):
"""Uses the Partition SHAP method to expla... |
class PartitionExplainer(Explainer):
'''Uses the Partition SHAP method to explain the output of any function.
Partition SHAP computes Shapley values recursively through a hierarchy of features, this
hierarchy defines feature coalitions and results in the Owen values from game theory.
The PartitionExpla... | 9 | 6 | 21 | 0 | 21 | 0 | 1 | 0.05 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 23 | 0 | 22 | 12 | 10 | 1 | 3 | 2 | 1 | 1 | 1 | 0 | 1 |
15,326 | slundberg/shap | slundberg_shap/shap/explainers/_permutation.py | shap.explainers._permutation.PermutationExplainer | from ..models import Model
from ..utils import MaskedModel, partition_tree_shuffle
import numpy as np
from ._explainer import Explainer
from .. import links
class PermutationExplainer(Explainer):
"""This method approximates the Shapley values by iterating through permutations of the inputs.
This is a model ag... |
class PermutationExplainer(Explainer):
'''This method approximates the Shapley values by iterating through permutations of the inputs.
This is a model agnostic explainer that guarantees local accuracy (additivity) by iterating completely
through an entire permutation of the features in both forward and rev... | 8 | 5 | 41 | 4 | 28 | 9 | 5 | 0.45 | 1 | 9 | 3 | 0 | 5 | 2 | 5 | 14 | 246 | 32 | 149 | 46 | 121 | 67 | 85 | 26 | 77 | 21 | 2 | 4 | 30 |
15,327 | slundberg/shap | slundberg_shap/shap/explainers/_permutation.py | shap.explainers._permutation.PermutationExplainer.__init__.PermutationExplainer | from ..models import Model
from .. import links
from ..utils import MaskedModel, partition_tree_shuffle
from ._explainer import Explainer
import numpy as np
class PermutationExplainer(Explainer):
"""This method approximates the Shapley values by iterating through permutations of the inputs.
This is a model ag... |
class PermutationExplainer(Explainer):
'''This method approximates the Shapley values by iterating through permutations of the inputs.
This is a model agnostic explainer that guarantees local accuracy (additivity) by iterating completely
through an entire permutation of the features in both forward and rev... | 8 | 5 | 19 | 0 | 19 | 0 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 20 | 0 | 20 | 11 | 9 | 0 | 3 | 2 | 1 | 1 | 1 | 0 | 1 |
15,328 | slundberg/shap | slundberg_shap/shap/explainers/_sampling.py | shap.explainers._sampling.SamplingExplainer | import numpy as np
from .._explanation import Explanation
import pandas as pd
from ..utils._exceptions import ExplainerError
from ._kernel import KernelExplainer
import logging
from ..utils._legacy import convert_to_instance, match_instance_to_data
class SamplingExplainer(KernelExplainer):
"""Computes SHAP values ... |
class SamplingExplainer(KernelExplainer):
'''Computes SHAP values using an extension of the Shapley sampling values explanation method
(also known as IME).
SamplingExplainer computes SHAP values under the assumption of feature independence and is an
extension of the algorithm proposed in "An Efficient ... | 5 | 1 | 39 | 6 | 29 | 6 | 8 | 0.41 | 1 | 10 | 2 | 0 | 4 | 6 | 4 | 24 | 189 | 30 | 115 | 43 | 110 | 47 | 105 | 43 | 100 | 23 | 3 | 3 | 30 |
15,329 | slundberg/shap | slundberg_shap/shap/explainers/_tree.py | shap.explainers._tree.CatBoostTreeModelLoader | import json
import os
import numpy as np
class CatBoostTreeModelLoader:
def __init__(self, cb_model):
import tempfile
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_file = os.path.join(tmp_dir, 'model.json')
cb_model.save_model(tmp_file, format='json')
with ... |
class CatBoostTreeModelLoader:
def __init__(self, cb_model):
pass
def get_trees(self, data=None, data_missing=None):
pass | 3 | 0 | 44 | 7 | 33 | 5 | 5 | 0.14 | 0 | 4 | 1 | 0 | 2 | 3 | 2 | 2 | 90 | 15 | 66 | 29 | 62 | 9 | 48 | 27 | 44 | 8 | 0 | 3 | 9 |
15,330 | slundberg/shap | slundberg_shap/shap/explainers/_tree.py | shap.explainers._tree.IsoTree | from ..utils import assert_import, record_import_error, safe_isinstance
import numpy as np
class IsoTree(SingleTree):
"""In sklearn the tree of the Isolation Forest does not calculated in a good way."""
def __init__(self, tree, tree_features, normalize=False, scaling=1.0, data=None, data_missing=None):
... |
class IsoTree(SingleTree):
'''In sklearn the tree of the Isolation Forest does not calculated in a good way.'''
def __init__(self, tree, tree_features, normalize=False, scaling=1.0, data=None, data_missing=None):
pass
def _recalculate_value(tree, i, level):
pass | 3 | 1 | 16 | 1 | 15 | 1 | 3 | 0.1 | 1 | 1 | 0 | 0 | 1 | 2 | 1 | 2 | 25 | 3 | 20 | 9 | 16 | 2 | 19 | 9 | 15 | 3 | 1 | 2 | 5 |
15,331 | slundberg/shap | slundberg_shap/shap/explainers/_tree.py | shap.explainers._tree.SingleTree | from ..utils import assert_import, record_import_error, safe_isinstance
import numpy as np
class SingleTree:
"""A single decision tree.
The primary point of this object is to parse many different tree types into a common format.
Attributes
----------
children_left : numpy.array
A 1d array... |
class SingleTree:
'''A single decision tree.
The primary point of this object is to parse many different tree types into a common format.
Attributes
----------
children_left : numpy.array
A 1d array of length #nodes. The index ``i`` of this array contains the index of
the left-child... | 6 | 1 | 68 | 6 | 58 | 7 | 7 | 0.26 | 0 | 8 | 0 | 1 | 1 | 8 | 1 | 1 | 328 | 36 | 237 | 54 | 231 | 62 | 193 | 53 | 187 | 22 | 0 | 4 | 34 |
15,332 | slundberg/shap | slundberg_shap/shap/explainers/_tree.py | shap.explainers._tree.TreeEnsemble | from ..utils import assert_import, record_import_error, safe_isinstance
import pandas as pd
import numpy as np
from ..utils._exceptions import DimensionError, ExplainerError, InvalidFeaturePerturbationError, InvalidMaskerError, InvalidModelError
import warnings
import scipy.special
import scipy.sparse
class TreeEnsemb... |
class TreeEnsemble:
'''An ensemble of decision trees.
This object provides a common interface to many different types of models.
'''
def __init__(self, model, data=None, data_missing=None, model_output=None):
pass
def _set_xgboost_model_attributes(self, data, data_missing, objective_name_... | 7 | 3 | 152 | 7 | 135 | 15 | 22 | 0.12 | 0 | 18 | 5 | 0 | 5 | 27 | 5 | 5 | 771 | 42 | 679 | 73 | 664 | 79 | 378 | 66 | 370 | 82 | 0 | 3 | 112 |
15,333 | slundberg/shap | slundberg_shap/shap/explainers/_tree.py | shap.explainers._tree.TreeExplainer | import scipy.sparse
from ..utils._legacy import DenseData
from ..utils import assert_import, record_import_error, safe_isinstance
import pandas as pd
from .._explanation import Explanation
import numpy as np
from .. import maskers
from typing import Any
from packaging import version
from ._explainer import Explainer
fr... |
class TreeExplainer(Explainer):
'''Uses Tree SHAP algorithms to explain the output of ensemble tree models.
Tree SHAP is a fast and exact method to estimate SHAP values for tree models
and ensembles of trees, under several different possible assumptions about
feature dependence. It depends on fast C++ ... | 13 | 9 | 68 | 8 | 43 | 18 | 9 | 0.45 | 1 | 22 | 8 | 1 | 9 | 7 | 10 | 19 | 756 | 99 | 458 | 81 | 414 | 205 | 257 | 54 | 239 | 30 | 2 | 4 | 104 |
15,334 | slundberg/shap | slundberg_shap/shap/explainers/_tree.py | shap.explainers._tree.XGBTreeModelLoader | import scipy.special
import scipy.sparse
import numpy as np
from .other._ubjson import decode_ubjson_buffer
import io
class XGBTreeModelLoader:
"""This loads an XGBoost model directly from a raw memory dump."""
def __init__(self, xgb_model) -> None:
import xgboost as xgb
_check_xgboost_version... |
class XGBTreeModelLoader:
'''This loads an XGBoost model directly from a raw memory dump.'''
def __init__(self, xgb_model) -> None:
pass
def to_integers(data: list[int]) -> np.ndarray:
'''Handle u8 array from UBJSON.'''
pass
@staticmethod
def parse_cate... | 7 | 3 | 43 | 5 | 32 | 6 | 4 | 0.2 | 0 | 7 | 1 | 0 | 3 | 20 | 4 | 4 | 218 | 30 | 158 | 79 | 144 | 31 | 129 | 71 | 122 | 10 | 0 | 3 | 19 |
15,335 | slundberg/shap | slundberg_shap/shap/explainers/other/_coefficient.py | shap.explainers.other._coefficient.Coefficient | import numpy as np
from .._explainer import Explainer
class Coefficient(Explainer):
"""Simply returns the model coefficients as the feature attributions.
This is only for benchmark comparisons and does not approximate SHAP values in a
meaningful way.
"""
def __init__(self, model):
assert ... |
class Coefficient(Explainer):
'''Simply returns the model coefficients as the feature attributions.
This is only for benchmark comparisons and does not approximate SHAP values in a
meaningful way.
'''
def __init__(self, model):
pass
def attributions(self, X):
pass | 3 | 1 | 3 | 0 | 3 | 0 | 1 | 0.67 | 1 | 0 | 0 | 0 | 2 | 1 | 2 | 11 | 13 | 3 | 6 | 4 | 3 | 4 | 6 | 4 | 3 | 1 | 2 | 0 | 2 |
15,336 | slundberg/shap | slundberg_shap/shap/explainers/other/_lime.py | shap.explainers.other._lime.LimeTabular | import pandas as pd
from .._explainer import Explainer
import numpy as np
class LimeTabular(Explainer):
"""Simply wrap of lime.lime_tabular.LimeTabularExplainer into the common shap interface.
Parameters
----------
model : function or iml.Model
User supplied function that takes a matrix of sam... |
class LimeTabular(Explainer):
'''Simply wrap of lime.lime_tabular.LimeTabularExplainer into the common shap interface.
Parameters
----------
model : function or iml.Model
User supplied function that takes a matrix of samples (# samples x # features) and
computes the output of the model ... | 4 | 1 | 17 | 3 | 14 | 1 | 5 | 0.35 | 1 | 2 | 0 | 0 | 2 | 6 | 2 | 11 | 67 | 14 | 40 | 18 | 36 | 14 | 37 | 18 | 33 | 9 | 2 | 3 | 15 |
15,337 | slundberg/shap | slundberg_shap/shap/explainers/other/_maple.py | shap.explainers.other._maple.MAPLE | import numpy as np
from sklearn.linear_model import Ridge
from sklearn.ensemble import GradientBoostingRegressor, RandomForestRegressor
from sklearn.metrics import mean_squared_error
class MAPLE:
def __init__(self, X_train, MR_train, X_val, MR_val, fe_type='rf', fe=None, n_estimators=200, max_features=0.5, min_sa... |
class MAPLE:
def __init__(self, X_train, MR_train, X_val, MR_val, fe_type='rf', fe=None, n_estimators=200, max_features=0.5, min_samples_leaf=10, regularization=0.001):
pass
def training_point_weights(self, instance_leaf_ids):
pass
def explain(self, x):
pass
def predict(self... | 7 | 0 | 28 | 4 | 21 | 3 | 4 | 0.17 | 0 | 5 | 0 | 0 | 6 | 15 | 6 | 6 | 173 | 31 | 126 | 75 | 106 | 22 | 101 | 63 | 93 | 13 | 0 | 3 | 22 |
15,338 | slundberg/shap | slundberg_shap/shap/explainers/other/_maple.py | shap.explainers.other._maple.Maple | from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
from .._explainer import Explainer
class Maple(Explainer):
"""Simply wraps MAPLE into the common SHAP interface.
Parameters
----------
model : function
User supplied function that takes a matrix of samp... |
class Maple(Explainer):
'''Simply wraps MAPLE into the common SHAP interface.
Parameters
----------
model : function
User supplied function that takes a matrix of samples (# samples x # features) and
computes the output of the model for those samples. The output can be a vector
... | 3 | 2 | 19 | 3 | 13 | 4 | 4 | 0.65 | 1 | 2 | 1 | 0 | 2 | 6 | 2 | 11 | 53 | 10 | 26 | 14 | 23 | 17 | 25 | 14 | 22 | 5 | 2 | 2 | 8 |
15,339 | slundberg/shap | slundberg_shap/shap/explainers/other/_maple.py | shap.explainers.other._maple.TreeMaple | import numpy as np
from .._explainer import Explainer
import pandas as pd
class TreeMaple(Explainer):
"""Simply tree MAPLE into the common SHAP interface.
Parameters
----------
model : function
User supplied function that takes a matrix of samples (# samples x # features) and
computes ... |
class TreeMaple(Explainer):
'''Simply tree MAPLE into the common SHAP interface.
Parameters
----------
model : function
User supplied function that takes a matrix of samples (# samples x # features) and
computes the output of the model for those samples. The output can be a vector
... | 3 | 2 | 28 | 4 | 17 | 8 | 5 | 0.76 | 1 | 5 | 1 | 0 | 2 | 6 | 2 | 11 | 71 | 11 | 34 | 15 | 31 | 26 | 29 | 15 | 26 | 5 | 2 | 2 | 10 |
15,340 | slundberg/shap | slundberg_shap/shap/explainers/other/_random.py | shap.explainers.other._random.Random | from shap.models import Model
from .._explainer import Explainer
import numpy as np
from shap import links
from shap.utils import MaskedModel
class Random(Explainer):
"""Simply returns random (normally distributed) feature attributions.
This is only for benchmark comparisons. It supports both fully random att... |
class Random(Explainer):
'''Simply returns random (normally distributed) feature attributions.
This is only for benchmark comparisons. It supports both fully random attributions and random
attributions that are constant across all explanations.
'''
def __init__(self, model, masker, link=links.iden... | 3 | 2 | 24 | 4 | 18 | 3 | 4 | 0.28 | 1 | 5 | 2 | 1 | 2 | 3 | 2 | 11 | 56 | 10 | 36 | 14 | 31 | 10 | 22 | 12 | 19 | 5 | 2 | 2 | 8 |
15,341 | slundberg/shap | slundberg_shap/shap/explainers/other/_treegain.py | shap.explainers.other._treegain.TreeGain | from .._explainer import Explainer
import numpy as np
class TreeGain(Explainer):
"""Simply returns the global gain/gini feature importances for tree models.
This is only for benchmark comparisons and is not meant to approximate SHAP values.
"""
def __init__(self, model):
if str(type(model)).e... |
class TreeGain(Explainer):
'''Simply returns the global gain/gini feature importances for tree models.
This is only for benchmark comparisons and is not meant to approximate SHAP values.
'''
def __init__(self, model):
pass
def attributions(self, X):
pass | 3 | 1 | 11 | 0 | 11 | 0 | 4 | 0.14 | 1 | 3 | 0 | 0 | 2 | 1 | 2 | 11 | 28 | 3 | 22 | 4 | 19 | 3 | 14 | 4 | 11 | 7 | 2 | 1 | 8 |
15,342 | slundberg/shap | slundberg_shap/shap/explainers/pytree.py | shap.explainers.pytree.Tree | import numpy as np
class Tree:
def __init__(self, tree, normalize=False):
if str(type(tree)).endswith("'sklearn.tree._tree.Tree'>"):
self.children_left = tree.children_left.astype(np.int32)
self.children_right = tree.children_right.astype(np.int32)
self.children_default... |
class Tree:
def __init__(self, tree, normalize=False):
pass | 2 | 0 | 18 | 2 | 15 | 2 | 3 | 0.88 | 0 | 2 | 0 | 0 | 1 | 8 | 1 | 1 | 33 | 4 | 16 | 10 | 14 | 14 | 13 | 10 | 11 | 3 | 0 | 2 | 3 |
15,343 | slundberg/shap | slundberg_shap/shap/explainers/pytree.py | shap.explainers.pytree.TreeExplainer | import numpy as np
from ..utils._exceptions import ExplainerError
import pandas as pd
class TreeExplainer:
"""A pure Python (slow) implementation of Tree SHAP."""
def __init__(self, model, **kwargs):
self.model_type = 'internal'
if str(type(model)).endswith("sklearn.ensemble.forest.RandomFores... |
class TreeExplainer:
'''A pure Python (slow) implementation of Tree SHAP.'''
def __init__(self, model, **kwargs):
pass
def shap_values(self, X, tree_limit=-1, **kwargs):
pass
def shap_interaction_values(self, X, tree_limit=-1, **kwargs):
pass
def tree_shap(self, tree, x,... | 5 | 1 | 29 | 3 | 24 | 2 | 6 | 0.11 | 0 | 8 | 2 | 0 | 4 | 6 | 4 | 4 | 121 | 16 | 95 | 19 | 88 | 10 | 63 | 19 | 56 | 13 | 0 | 3 | 25 |
15,344 | slundberg/shap | slundberg_shap/shap/maskers/_composite.py | shap.maskers._composite.Composite | from ._masker import Masker
from ..utils._exceptions import InvalidMaskerError
import types
class Composite(Masker):
"""This merges several maskers for different inputs together into a single composite masker.
This is not yet implemented.
"""
def __init__(self, *maskers):
self.maskers = maske... |
class Composite(Masker):
'''This merges several maskers for different inputs together into a single composite masker.
This is not yet implemented.
'''
def __init__(self, *maskers):
pass
def shape(self, *args):
'''Compute the shape of this masker as the sum of all the sub masker sh... | 6 | 4 | 22 | 3 | 18 | 1 | 4 | 0.11 | 1 | 4 | 1 | 0 | 5 | 6 | 5 | 10 | 119 | 19 | 92 | 38 | 86 | 10 | 82 | 37 | 76 | 8 | 2 | 2 | 22 |
15,345 | slundberg/shap | slundberg_shap/shap/maskers/_fixed.py | shap.maskers._fixed.Fixed | import numpy as np
from ._masker import Masker
class Fixed(Masker):
"""This leaves the input unchanged during masking, and is used for things like scoring labels.
Sometimes there are inputs to the model that we do not want to explain, but rather we want to
consider them fixed. The primary example of this ... |
class Fixed(Masker):
'''This leaves the input unchanged during masking, and is used for things like scoring labels.
Sometimes there are inputs to the model that we do not want to explain, but rather we want to
consider them fixed. The primary example of this is when we explain the loss of the model using
... | 4 | 2 | 3 | 0 | 2 | 0 | 1 | 1.13 | 1 | 0 | 0 | 0 | 3 | 2 | 3 | 8 | 21 | 4 | 8 | 6 | 4 | 9 | 8 | 6 | 4 | 1 | 2 | 0 | 3 |
15,346 | slundberg/shap | slundberg_shap/shap/maskers/_fixed_composite.py | shap.maskers._fixed_composite.FixedComposite | from ._masker import Masker
import numpy as np
from .._serializable import Deserializer, Serializer
class FixedComposite(Masker):
"""A masker that outputs both the masked data and the original data as a pair."""
def __init__(self, masker):
"""Creates a Composite masker from an underlying masker and re... |
class FixedComposite(Masker):
'''A masker that outputs both the masked data and the original data as a pair.'''
def __init__(self, masker):
'''Creates a Composite masker from an underlying masker and returns the original args along with the masked output.
Parameters
----------
... | 6 | 5 | 14 | 2 | 9 | 4 | 2 | 0.43 | 1 | 4 | 2 | 0 | 3 | 1 | 4 | 9 | 63 | 10 | 37 | 16 | 31 | 16 | 27 | 13 | 22 | 3 | 2 | 2 | 9 |
15,347 | slundberg/shap | slundberg_shap/shap/maskers/_image.py | shap.maskers._image.Image | import numba.typed
from ..utils import assert_import, record_import_error, safe_isinstance
from ._masker import Masker
from .._serializable import Deserializer, Serializer
import numpy as np
from ..utils._exceptions import DimensionError
class Image(Masker):
"""Masks out image regions with blurring or inpainting."... |
class Image(Masker):
'''Masks out image regions with blurring or inpainting.'''
def __init__(self, mask_value, shape=None):
'''Build a new Image masker with the given masking value.
Parameters
----------
mask_value : np.array, "blur(kernel_xsize, kernel_xsize)", "inpaint_telea"... | 8 | 6 | 24 | 3 | 17 | 4 | 4 | 0.24 | 1 | 12 | 3 | 0 | 5 | 11 | 6 | 11 | 153 | 25 | 105 | 37 | 97 | 25 | 81 | 34 | 74 | 11 | 2 | 3 | 23 |
15,348 | slundberg/shap | slundberg_shap/shap/maskers/_masker.py | shap.maskers._masker.Masker | from .._serializable import Serializable
import numpy as np
class Masker(Serializable):
"""This is the superclass of all maskers."""
def __call__(self, mask, *args):
"""Maskers are callable objects that accept the same inputs as the model plus a binary mask."""
def _standardize_mask(self, mask, *... | null | 3 | 3 | 7 | 1 | 6 | 1 | 3 | 0.25 | 1 | 1 | 0 | 8 | 2 | 0 | 2 | 5 | 18 | 3 | 12 | 4 | 9 | 3 | 11 | 4 | 8 | 4 | 1 | 2 | 5 |
15,349 | slundberg/shap | slundberg_shap/shap/maskers/_output_composite.py | shap.maskers._output_composite.OutputComposite | from ._masker import Masker
from .._serializable import Deserializer, Serializer
class OutputComposite(Masker):
"""A masker that is a combination of a masker and a model and outputs both masked args and the model's output."""
def __init__(self, masker, model):
"""Creates a masker from an underlying ma... |
class OutputComposite(Masker):
'''A masker that is a combination of a masker and a model and outputs both masked args and the model's output.'''
def __init__(self, masker, model):
'''Creates a masker from an underlying masker and and model.
This masker returns the masked input along with the m... | 6 | 5 | 16 | 2 | 9 | 5 | 2 | 0.54 | 1 | 4 | 2 | 0 | 3 | 2 | 4 | 9 | 72 | 12 | 39 | 15 | 33 | 21 | 29 | 12 | 24 | 3 | 2 | 2 | 9 |
15,350 | slundberg/shap | slundberg_shap/shap/maskers/_tabular.py | shap.maskers._tabular.Impute | from ._masker import Masker
import numpy as np
class Impute(Masker):
"""This imputes the values of missing features using the values of the observed features.
Unlike Independent, Gaussian imputes missing values based on correlations with observed data points.
"""
def __init__(self, data, method='line... |
class Impute(Masker):
'''This imputes the values of missing features using the values of the observed features.
Unlike Independent, Gaussian imputes missing values based on correlations with observed data points.
'''
def __init__(self, data, method='linear'):
'''Build a Partition masker with t... | 2 | 2 | 16 | 3 | 7 | 6 | 2 | 1.25 | 1 | 1 | 0 | 0 | 1 | 4 | 1 | 6 | 22 | 5 | 8 | 6 | 6 | 10 | 8 | 6 | 6 | 2 | 2 | 1 | 2 |
15,351 | slundberg/shap | slundberg_shap/shap/maskers/_tabular.py | shap.maskers._tabular.Independent | class Independent(Tabular):
"""This masks out tabular features by integrating over the given background dataset."""
def __init__(self, data, max_samples=100):
"""Build a Independent masker with the given background data.
Parameters
----------
data : numpy.ndarray, pandas.DataFr... | class Independent(Tabular):
'''This masks out tabular features by integrating over the given background dataset.'''
def __init__(self, data, max_samples=100):
'''Build a Independent masker with the given background data.
Parameters
----------
data : numpy.ndarray, pandas.DataFra... | 2 | 2 | 17 | 3 | 2 | 12 | 1 | 4.33 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 11 | 20 | 4 | 3 | 2 | 1 | 13 | 3 | 2 | 1 | 1 | 3 | 0 | 1 |
15,352 | slundberg/shap | slundberg_shap/shap/maskers/_tabular.py | shap.maskers._tabular.Partition | class Partition(Tabular):
"""This masks out tabular features by integrating over the given background dataset.
Unlike Independent, Partition respects a hierarchical structure of the data.
"""
def __init__(self, data, max_samples=100, clustering='correlation'):
"""Build a Partition masker with ... | class Partition(Tabular):
'''This masks out tabular features by integrating over the given background dataset.
Unlike Independent, Partition respects a hierarchical structure of the data.
'''
def __init__(self, data, max_samples=100, clustering='correlation'):
'''Build a Partition masker with t... | 2 | 2 | 28 | 4 | 2 | 22 | 1 | 8.33 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 11 | 34 | 6 | 3 | 2 | 1 | 25 | 3 | 2 | 1 | 1 | 3 | 0 | 1 |
15,353 | slundberg/shap | slundberg_shap/shap/maskers/_tabular.py | shap.maskers._tabular.Tabular | from ..utils import MaskedModel
import numpy as np
from .._serializable import Deserializer, Serializer
from .. import utils
from ..utils._exceptions import DimensionError, InvalidClusteringError
from ._masker import Masker
import pandas as pd
class Tabular(Masker):
"""A common base class for Independent and Parti... |
class Tabular(Masker):
'''A common base class for Independent and Partition.'''
def __init__(self, data, max_samples=100, clustering=None, partition=None):
'''This masks out tabular features by integrating over the given background dataset.
Parameters
----------
data : np.array... | 7 | 5 | 30 | 4 | 18 | 8 | 4 | 0.53 | 1 | 10 | 5 | 2 | 4 | 11 | 5 | 10 | 173 | 29 | 94 | 26 | 87 | 50 | 69 | 23 | 63 | 7 | 2 | 2 | 19 |
15,354 | slundberg/shap | slundberg_shap/shap/maskers/_text.py | shap.maskers._text.SimpleTokenizer | import re
class SimpleTokenizer:
"""A basic model agnostic tokenizer."""
def __init__(self, split_pattern='\\W+'):
"""Create a tokenizer based on a simple splitting pattern."""
self.split_pattern = re.compile(split_pattern)
def __call__(self, s, return_offsets_mapping=True):
"""To... | null | 3 | 3 | 11 | 1 | 10 | 1 | 3 | 0.15 | 0 | 0 | 0 | 0 | 2 | 1 | 2 | 2 | 26 | 3 | 20 | 10 | 17 | 3 | 20 | 10 | 17 | 4 | 0 | 1 | 5 |
15,355 | slundberg/shap | slundberg_shap/shap/maskers/_text.py | shap.maskers._text.Text | from ._masker import Masker
import re
from ..utils import safe_isinstance
from ..utils.transformers import SENTENCEPIECE_TOKENIZERS, getattr_silent, parse_prefix_suffix_for_tokenizer
from .._serializable import Deserializer, Serializer
import numpy as np
class Text(Masker):
"""This masks out tokens according to th... |
class Text(Masker):
'''This masks out tokens according to the given tokenizer.
The masked variables are
output_type : "string" (default) or "token_ids"
'''
def __init__(self, tokenizer=None, mask_token=None, collapse_mask_token='auto', output_type='string'):
'''Build a new Text masker give... | 14 | 11 | 23 | 3 | 15 | 6 | 4 | 0.55 | 1 | 11 | 3 | 0 | 11 | 16 | 12 | 17 | 334 | 54 | 184 | 58 | 170 | 101 | 156 | 54 | 143 | 13 | 2 | 4 | 51 |
15,356 | slundberg/shap | slundberg_shap/shap/maskers/_text.py | shap.maskers._text.Token | class Token:
"""A token representation used for token clustering."""
def __init__(self, value):
self.s = value
if value in openers or value in closers:
self.balanced = False
else:
self.balanced = True
def __str__(self):
return self.s
def __repr_... | class Token:
'''A token representation used for token clustering.'''
def __init__(self, value):
pass
def __str__(self):
pass
def __repr__(self):
pass | 4 | 1 | 4 | 0 | 4 | 0 | 2 | 0.08 | 0 | 0 | 0 | 0 | 3 | 2 | 3 | 3 | 17 | 3 | 13 | 6 | 9 | 1 | 12 | 6 | 8 | 2 | 0 | 1 | 5 |
15,357 | slundberg/shap | slundberg_shap/shap/maskers/_text.py | shap.maskers._text.TokenGroup | class TokenGroup:
"""A token group (substring) representation used for token clustering."""
def __init__(self, group, index=None):
self.g = group
self.index = index
def __repr__(self):
return self.g.__repr__()
def __getitem__(self, index):
return self.g[index]
def... | class TokenGroup:
'''A token group (substring) representation used for token clustering.'''
def __init__(self, group, index=None):
pass
def __repr__(self):
pass
def __getitem__(self, index):
pass
def __add__(self, o):
pass
def __len__(self):
pass | 6 | 1 | 2 | 0 | 2 | 0 | 1 | 0.08 | 0 | 0 | 0 | 0 | 5 | 2 | 5 | 5 | 18 | 5 | 12 | 8 | 6 | 1 | 12 | 8 | 6 | 1 | 0 | 0 | 5 |
15,358 | slundberg/shap | slundberg_shap/shap/models/_model.py | shap.models._model.Model | from .._serializable import Deserializer, Serializable, Serializer
from ..utils import safe_isinstance
from typing import Any
import numpy as np
class Model(Serializable):
"""This is the superclass of all models."""
def __init__(self, model=None):
"""Wrap a callable model as a SHAP Model object."""
... |
class Model(Serializable):
'''This is the superclass of all models.'''
def __init__(self, model=None):
'''Wrap a callable model as a SHAP Model object.'''
pass
def __call__(self, *args):
pass
def save(self, out_file):
'''Save the model to the given file stream.'''
... | 6 | 3 | 7 | 1 | 6 | 1 | 2 | 0.12 | 1 | 4 | 2 | 4 | 3 | 2 | 4 | 7 | 34 | 6 | 25 | 13 | 19 | 3 | 23 | 10 | 18 | 3 | 1 | 1 | 8 |
15,359 | slundberg/shap | slundberg_shap/shap/models/_teacher_forcing.py | shap.models._teacher_forcing.TeacherForcing | from .._serializable import Deserializer, Serializer
from ..utils import safe_isinstance
import scipy.special
from ..utils.transformers import getattr_silent, parse_prefix_suffix_for_tokenizer
from ._model import Model
from typing import Any
import numpy as np
import inspect
from .. import models
class TeacherForcing(... |
class TeacherForcing(Model):
'''Generates scores (log odds) for output text explanation algorithms using Teacher Forcing technique.
This class supports generation of log odds for transformer models as well as functions. In model agnostic
cases (model is function) it expects a similarity_model and similarit... | 14 | 10 | 34 | 4 | 19 | 12 | 4 | 0.68 | 1 | 10 | 3 | 0 | 10 | 11 | 11 | 18 | 427 | 60 | 220 | 60 | 202 | 149 | 165 | 54 | 150 | 10 | 2 | 5 | 43 |
15,360 | slundberg/shap | slundberg_shap/shap/models/_text_generation.py | shap.models._text_generation.TextGeneration | import numpy as np
from ..utils import safe_isinstance
from .._serializable import Deserializer, Serializer
from ._model import Model
class TextGeneration(Model):
"""Generates target sentence/ids using a base model.
It generates target sentence/ids for a model (a pretrained transformer model or a function).
... |
class TextGeneration(Model):
'''Generates target sentence/ids using a base model.
It generates target sentence/ids for a model (a pretrained transformer model or a function).
'''
def __init__(self, model=None, tokenizer=None, target_sentences=None, device=None):
'''Create a text generator mode... | 9 | 6 | 32 | 4 | 16 | 12 | 4 | 0.75 | 1 | 8 | 2 | 0 | 6 | 8 | 7 | 14 | 238 | 34 | 117 | 32 | 106 | 88 | 94 | 28 | 84 | 15 | 2 | 4 | 31 |
15,361 | slundberg/shap | slundberg_shap/shap/models/_topk_lm.py | shap.models._topk_lm.TopKLM | from ..utils import safe_isinstance
import scipy.special
from ..utils.transformers import getattr_silent
from .._serializable import Deserializer, Serializer
from ._model import Model
import numpy as np
class TopKLM(Model):
"""Generates scores (log odds) for the top-k tokens for Causal/Masked LM."""
def __ini... |
class TopKLM(Model):
'''Generates scores (log odds) for the top-k tokens for Causal/Masked LM.'''
def __init__(self, model, tokenizer, k=10, generate_topk_token_ids=None, batch_size=128, device=None):
'''Take Causal/Masked LM model and tokenizer and build a log odds output model for the top-k tokens.
... | 13 | 9 | 24 | 4 | 11 | 9 | 2 | 0.87 | 1 | 6 | 2 | 0 | 9 | 10 | 10 | 17 | 268 | 53 | 115 | 46 | 98 | 100 | 107 | 42 | 91 | 6 | 2 | 5 | 26 |
15,362 | slundberg/shap | slundberg_shap/shap/models/_transformers_pipeline.py | shap.models._transformers_pipeline.TransformersPipeline | import scipy.special
from ._model import Model
import numpy as np
class TransformersPipeline(Model):
"""This wraps a transformers pipeline object for easy explanations.
By default transformers pipeline object output lists of dictionaries, not standard
tensors as expected by SHAP. This class wraps pipeline... |
class TransformersPipeline(Model):
'''This wraps a transformers pipeline object for easy explanations.
By default transformers pipeline object output lists of dictionaries, not standard
tensors as expected by SHAP. This class wraps pipelines to make them output nice
tensor formats.
'''
def __i... | 3 | 2 | 13 | 1 | 11 | 2 | 4 | 0.35 | 1 | 5 | 0 | 0 | 2 | 5 | 2 | 9 | 34 | 4 | 23 | 12 | 20 | 8 | 19 | 12 | 16 | 5 | 2 | 2 | 7 |
15,363 | slundberg/shap | slundberg_shap/shap/plots/_decision.py | shap.plots._decision.DecisionPlotResult | class DecisionPlotResult:
"""The optional return value of decision_plot.
The class attributes can be used to apply the same scale and feature ordering to other decision plots.
"""
def __init__(self, base_value, shap_values, feature_names, feature_idx, xlim):
"""Example
-------
... | null | 2 | 2 | 36 | 6 | 6 | 24 | 1 | 3.86 | 0 | 0 | 0 | 0 | 1 | 5 | 1 | 1 | 42 | 8 | 7 | 7 | 5 | 27 | 7 | 7 | 5 | 1 | 0 | 0 | 1 |
15,364 | slundberg/shap | slundberg_shap/shap/plots/_force.py | shap.plots._force.AdditiveExplanation | from ..utils._legacy import Data, DenseData, Instance, Link, Model, convert_to_link
class AdditiveExplanation(Explanation):
"""Data structure for AdditiveForceVisualizer / AdditiveForceArrayVisualizer."""
def __init__(self, base_value, out_value, effects, effects_var, instance, link, model, data):
"""... |
class AdditiveExplanation(Explanation):
'''Data structure for AdditiveForceVisualizer / AdditiveForceArrayVisualizer.'''
def __init__(self, base_value, out_value, effects, effects_var, instance, link, model, data):
'''Parameters
----------
base_value : float
This is the ref... | 2 | 2 | 24 | 2 | 13 | 9 | 1 | 0.71 | 1 | 4 | 4 | 0 | 1 | 8 | 1 | 2 | 27 | 3 | 14 | 10 | 12 | 10 | 14 | 10 | 12 | 1 | 1 | 0 | 1 |
15,365 | slundberg/shap | slundberg_shap/shap/plots/_force.py | shap.plots._force.AdditiveForceArrayVisualizer | import numpy as np
from ..utils import hclust_ordering
import json
class AdditiveForceArrayVisualizer(BaseVisualizer):
"""Visualizer for a sequence of AdditiveExplanation, as a stacked force plot."""
def __init__(self, arr, plot_cmap='RdBu', ordering_keys=None, ordering_keys_time_format=None):
if not ... |
class AdditiveForceArrayVisualizer(BaseVisualizer):
'''Visualizer for a sequence of AdditiveExplanation, as a stacked force plot.'''
def __init__(self, arr, plot_cmap='RdBu', ordering_keys=None, ordering_keys_time_format=None):
pass
def html(self):
pass
def _repr_html_(self):
... | 4 | 1 | 18 | 1 | 16 | 2 | 3 | 0.15 | 1 | 7 | 1 | 0 | 3 | 1 | 3 | 3 | 59 | 6 | 48 | 10 | 44 | 7 | 22 | 10 | 18 | 7 | 1 | 2 | 9 |
15,366 | slundberg/shap | slundberg_shap/shap/plots/_force.py | shap.plots._force.AdditiveForceVisualizer | import json
from ..plots._force_matplotlib import draw_additive_plot
class AdditiveForceVisualizer(BaseVisualizer):
"""Visualizer for a single Additive Force plot."""
def __init__(self, e, plot_cmap='RdBu'):
"""Parameters
----------
e : AdditiveExplanation
Contains the data... |
class AdditiveForceVisualizer(BaseVisualizer):
'''Visualizer for a single Additive Force plot.'''
def __init__(self, e, plot_cmap='RdBu'):
'''Parameters
----------
e : AdditiveExplanation
Contains the data necessary for additive force plots.
plot_cmap : str or list[... | 5 | 2 | 12 | 1 | 9 | 2 | 2 | 0.28 | 1 | 5 | 1 | 0 | 4 | 1 | 4 | 4 | 54 | 8 | 36 | 11 | 31 | 10 | 18 | 11 | 13 | 3 | 1 | 1 | 6 |
15,367 | slundberg/shap | slundberg_shap/shap/plots/_force.py | shap.plots._force.BaseVisualizer | class BaseVisualizer:
pass | class BaseVisualizer:
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 0 | 0 | 0 | 0 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 0 | 0 | 0 |
15,368 | slundberg/shap | slundberg_shap/shap/plots/_force.py | shap.plots._force.Explanation | class Explanation:
def __init__(self):
pass | class Explanation:
def __init__(self):
pass | 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 3 | 0 | 3 | 2 | 1 | 0 | 3 | 2 | 1 | 1 | 0 | 0 | 1 |
15,369 | slundberg/shap | slundberg_shap/shap/plots/_force.py | shap.plots._force.SimpleListVisualizer | import json
class SimpleListVisualizer(BaseVisualizer):
def __init__(self, e):
if not isinstance(e, Explanation):
emsg = 'SimpleListVisualizer can only visualize Explanation objects!'
raise TypeError(emsg)
features = {}
for i in filter(lambda j: e.effects[j] != 0, r... |
class SimpleListVisualizer(BaseVisualizer):
def __init__(self, e):
pass
def html(self):
pass
def _repr_html_(self):
pass | 4 | 0 | 10 | 0 | 9 | 1 | 2 | 0.07 | 1 | 5 | 1 | 0 | 3 | 1 | 3 | 3 | 33 | 3 | 28 | 9 | 24 | 2 | 14 | 9 | 10 | 3 | 1 | 1 | 5 |
15,370 | slundberg/shap | slundberg_shap/shap/plots/_style.py | shap.plots._style.StyleConfig | import dataclasses
@dataclasses.dataclass(frozen=True)
class StyleConfig:
"""A complete set of configuration options for matplotlib-based shap plots."""
primary_color_positive: ColorType
primary_color_negative: ColorType
secondary_color_positive: ColorType
secondary_color_negative: ColorType
hl... | @dataclasses.dataclass(frozen=True)
class StyleConfig:
'''A complete set of configuration options for matplotlib-based shap plots.'''
def asdict(self):
pass | 3 | 1 | 2 | 0 | 2 | 0 | 1 | 0.09 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 14 | 2 | 11 | 2 | 9 | 1 | 11 | 2 | 9 | 1 | 0 | 0 | 1 |
15,371 | slundberg/shap | slundberg_shap/shap/plots/_style.py | shap.plots._style.StyleOptions | from typing import TypedDict, Union
class StyleOptions(TypedDict, total=False):
"""A TypedDict of partial updates to a style configuration"""
primary_color_positive: ColorType
primary_color_negative: ColorType
secondary_color_positive: ColorType
secondary_color_negative: ColorType
hlines_color:... |
class StyleOptions(TypedDict, total=False):
'''A TypedDict of partial updates to a style configuration'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.44 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 14 | 1 | 9 | 1 | 8 | 4 | 9 | 1 | 8 | 0 | 1 | 0 | 0 |
15,372 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.ConvergenceError | class ConvergenceError(Exception):
pass | class ConvergenceError(Exception):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
15,373 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.DimensionError | class DimensionError(Exception):
"""Used for instances where dimensions are either
not supported or cause errors.
"""
pass | class DimensionError(Exception):
'''Used for instances where dimensions are either
not supported or cause errors.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 6 | 1 | 2 | 1 | 1 | 3 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
15,374 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.ExplainerError | class ExplainerError(Exception):
"""Generic errors related to Explainers"""
pass | class ExplainerError(Exception):
'''Generic errors related to Explainers'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0.5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 4 | 1 | 2 | 1 | 1 | 1 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
15,375 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.InvalidAction | class InvalidAction(Exception):
pass | class InvalidAction(Exception):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 3 | 0 | 0 |
15,376 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.InvalidAlgorithmError | class InvalidAlgorithmError(ValueError):
pass | class InvalidAlgorithmError(ValueError):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
15,377 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.InvalidClusteringError | class InvalidClusteringError(ValueError):
pass | class InvalidClusteringError(ValueError):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
15,378 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.InvalidFeaturePerturbationError | class InvalidFeaturePerturbationError(ValueError):
pass | class InvalidFeaturePerturbationError(ValueError):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
15,379 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.InvalidMaskerError | class InvalidMaskerError(ValueError):
pass | class InvalidMaskerError(ValueError):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
15,380 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.InvalidModelError | class InvalidModelError(ValueError):
pass | class InvalidModelError(ValueError):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
15,381 | slundberg/shap | slundberg_shap/shap/utils/_exceptions.py | shap.utils._exceptions.InvalidStyleOptionError | class InvalidStyleOptionError(ValueError):
pass | class InvalidStyleOptionError(ValueError):
pass | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 11 | 2 | 0 | 2 | 1 | 1 | 0 | 2 | 1 | 1 | 0 | 4 | 0 | 0 |
15,382 | slundberg/shap | slundberg_shap/shap/utils/_general.py | shap.utils._general.OpChain | import copy
from typing import TYPE_CHECKING, Any
class OpChain:
"""A way to represent a set of dot chained operations on an object without actually running them."""
def __init__(self, root_name: str='') -> None:
self._ops: list[list[Any]] = []
self._root_name = root_name
def apply(self, ... |
class OpChain:
'''A way to represent a set of dot chained operations on an object without actually running them.'''
def __init__(self, root_name: str='') -> None:
pass
def apply(self, obj):
'''Applies all our ops to the given object, usually an :class:`.Explanation` instance.'''
p... | 7 | 3 | 8 | 0 | 7 | 1 | 2 | 0.12 | 0 | 4 | 0 | 0 | 6 | 2 | 6 | 6 | 53 | 7 | 42 | 19 | 35 | 5 | 41 | 19 | 34 | 3 | 0 | 2 | 11 |
15,383 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.Data | class Data:
def __init__(self):
pass | class Data:
def __init__(self):
pass | 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 0 | 0 | 0 | 2 | 1 | 0 | 1 | 1 | 3 | 0 | 3 | 2 | 1 | 0 | 3 | 2 | 1 | 1 | 0 | 0 | 1 |
15,384 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.DenseData | import numpy as np
class DenseData(Data):
def __init__(self, data, group_names, *args):
self.groups = args[0] if len(args) > 0 and args[0] is not None else [np.array([i]) for i in range(len(group_names))]
j = sum((len(g) for g in self.groups))
num_samples = data.shape[0]
t = False
... |
class DenseData(Data):
def __init__(self, data, group_names, *args):
pass | 2 | 0 | 27 | 4 | 23 | 2 | 6 | 0.08 | 1 | 2 | 0 | 1 | 1 | 6 | 1 | 2 | 28 | 4 | 24 | 13 | 22 | 2 | 22 | 13 | 20 | 6 | 1 | 1 | 6 |
15,385 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.DenseDataWithIndex | import pandas as pd
class DenseDataWithIndex(DenseData):
def __init__(self, data, group_names, index, index_name, *args):
DenseData.__init__(self, data, group_names, *args)
self.index_value = index
self.index_name = index_name
def convert_to_df(self):
data = pd.DataFrame(self.... |
class DenseDataWithIndex(DenseData):
def __init__(self, data, group_names, index, index_name, *args):
pass
def convert_to_df(self):
pass | 3 | 0 | 5 | 0 | 5 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 2 | 3 | 2 | 4 | 12 | 1 | 11 | 8 | 8 | 0 | 11 | 8 | 8 | 1 | 2 | 0 | 2 |
15,386 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.IdentityLink | class IdentityLink(Link):
def __str__(self):
return 'identity'
@staticmethod
def f(x):
return x
@staticmethod
def finv(x):
return x | class IdentityLink(Link):
def __str__(self):
pass
@staticmethod
def f(x):
pass
@staticmethod
def finv(x):
pass | 6 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 3 | 4 | 11 | 2 | 9 | 6 | 3 | 0 | 7 | 4 | 3 | 1 | 1 | 0 | 3 |
15,387 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.Instance | class Instance:
def __init__(self, x, group_display_values):
self.x = x
self.group_display_values = group_display_values | class Instance:
def __init__(self, x, group_display_values):
pass | 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 2 | 1 | 1 | 4 | 0 | 4 | 4 | 2 | 0 | 4 | 4 | 2 | 1 | 0 | 0 | 1 |
15,388 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.InstanceWithIndex | import pandas as pd
class InstanceWithIndex(Instance):
def __init__(self, x, column_name, index_value, index_name, group_display_values):
Instance.__init__(self, x, group_display_values)
self.index_value = index_value
self.index_name = index_name
self.column_name = column_name
... |
class InstanceWithIndex(Instance):
def __init__(self, x, column_name, index_value, index_name, group_display_values):
pass
def convert_to_df(self):
pass | 3 | 0 | 6 | 0 | 6 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 2 | 4 | 2 | 3 | 13 | 1 | 12 | 9 | 9 | 0 | 12 | 9 | 9 | 1 | 1 | 0 | 2 |
15,389 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.Link | class Link:
def __init__(self):
pass | class Link:
def __init__(self):
pass | 2 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 0 | 0 | 0 | 2 | 1 | 0 | 1 | 1 | 3 | 0 | 3 | 2 | 1 | 0 | 3 | 2 | 1 | 1 | 0 | 0 | 1 |
15,390 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.LogitLink | import numpy as np
class LogitLink(Link):
def __str__(self):
return 'logit'
@staticmethod
def f(x, epsilon=1e-15):
x_clipped = np.clip(x, epsilon, 1 - epsilon)
return np.log(x_clipped / (1 - x_clipped))
@staticmethod
def finv(x):
return 1 / (1 + np.exp(-x)) |
class LogitLink(Link):
def __str__(self):
pass
@staticmethod
def f(x, epsilon=1e-15):
pass
@staticmethod
def finv(x):
pass | 6 | 0 | 2 | 0 | 2 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 3 | 4 | 12 | 2 | 10 | 7 | 4 | 0 | 8 | 5 | 4 | 1 | 1 | 0 | 3 |
15,391 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.Model | class Model:
def __init__(self, f, out_names):
self.f = f
self.out_names = out_names | class Model:
def __init__(self, f, out_names):
pass | 2 | 0 | 3 | 0 | 3 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 2 | 1 | 1 | 4 | 0 | 4 | 4 | 2 | 0 | 4 | 4 | 2 | 1 | 0 | 0 | 1 |
15,392 | slundberg/shap | slundberg_shap/shap/utils/_legacy.py | shap.utils._legacy.SparseData | import numpy as np
class SparseData(Data):
def __init__(self, data, *args):
num_samples = data.shape[0]
self.weights = np.ones(num_samples)
self.weights /= np.sum(self.weights)
self.transposed = False
self.groups = None
self.group_names = None
self.groups_si... |
class SparseData(Data):
def __init__(self, data, *args):
pass | 2 | 0 | 9 | 0 | 9 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 | 6 | 1 | 2 | 10 | 0 | 10 | 9 | 8 | 0 | 10 | 9 | 8 | 1 | 1 | 0 | 1 |
15,393 | slundberg/shap | slundberg_shap/shap/utils/_masked_model.py | shap.utils._masked_model.MaskedModel | import copy
from typing import Any
from .. import links
import numpy as np
class MaskedModel:
"""This is a utility class that combines a model, a masker object, and a current input.
The combination of a model, a masker object, and a current input produces a binary set
function that can be called to mask o... |
class MaskedModel:
'''This is a utility class that combines a model, a masker object, and a current input.
The combination of a model, a masker object, and a current input produces a binary set
function that can be called to mask out any set of inputs. This class attempts to be smart
about only evaluat... | 10 | 3 | 28 | 4 | 20 | 5 | 4 | 0.4 | 0 | 8 | 0 | 0 | 8 | 12 | 8 | 8 | 268 | 47 | 162 | 63 | 152 | 65 | 133 | 61 | 124 | 15 | 0 | 4 | 35 |
15,394 | slundberg/shap | slundberg_shap/shap/utils/_show_progress.py | shap.utils._show_progress.ShowProgress | import time
import tqdm
class ShowProgress:
"""This is a simple wrapper around tqdm that includes a starting delay before printing."""
def __init__(self, iterable, total, desc, silent, start_delay):
self.iter = iter(iterable)
self.start_time = time.time()
self.pbar = None
self.... |
class ShowProgress:
'''This is a simple wrapper around tqdm that includes a starting delay before printing.'''
def __init__(self, iterable, total, desc, silent, start_delay):
pass
def __next__(self):
pass
def __iter__(self):
pass | 4 | 1 | 8 | 0 | 8 | 0 | 2 | 0.04 | 0 | 2 | 0 | 0 | 3 | 8 | 3 | 3 | 30 | 3 | 26 | 12 | 22 | 1 | 25 | 12 | 21 | 5 | 0 | 2 | 7 |
15,395 | audreyr/cookiecutter | audreyr_cookiecutter/cookiecutter/environment.py | cookiecutter.environment.ExtensionLoaderMixin | from cookiecutter.exceptions import UnknownExtension
from typing import Any
class ExtensionLoaderMixin:
"""Mixin providing sane loading of extensions specified in a given context.
The context is being extracted from the keyword arguments before calling
the next parent class in line of the child.
"""
... |
class ExtensionLoaderMixin:
'''Mixin providing sane loading of extensions specified in a given context.
The context is being extracted from the keyword arguments before calling
the next parent class in line of the child.
'''
def __init__(self, *, context: dict[str, Any] | None=None, **kwargs: ... | 3 | 3 | 19 | 3 | 11 | 6 | 2 | 0.65 | 0 | 8 | 1 | 1 | 2 | 0 | 2 | 2 | 45 | 8 | 23 | 8 | 20 | 15 | 17 | 7 | 14 | 2 | 0 | 1 | 4 |
15,396 | audreyr/cookiecutter | audreyr_cookiecutter/cookiecutter/environment.py | cookiecutter.environment.StrictEnvironment | from jinja2 import Environment, StrictUndefined
from typing import Any
class StrictEnvironment(ExtensionLoaderMixin, Environment):
"""Create strict Jinja2 environment.
Jinja2 environment will raise error on undefined variable in template-
rendering context.
"""
def __init__(self, **kwargs: Any) -... |
class StrictEnvironment(ExtensionLoaderMixin, Environment):
'''Create strict Jinja2 environment.
Jinja2 environment will raise error on undefined variable in template-
rendering context.
'''
def __init__(self, **kwargs: Any) -> None:
'''Set the standard Cookiecutter StrictEnvironment.
... | 2 | 2 | 6 | 1 | 2 | 3 | 1 | 2.33 | 2 | 2 | 0 | 0 | 1 | 0 | 1 | 3 | 13 | 3 | 3 | 2 | 1 | 7 | 3 | 2 | 1 | 1 | 1 | 0 | 1 |
15,397 | audreyr/cookiecutter | audreyr_cookiecutter/cookiecutter/exceptions.py | cookiecutter.exceptions.ConfigDoesNotExistException | class ConfigDoesNotExistException(CookiecutterException):
"""
Exception for missing config file.
Raised when get_config() is passed a path to a config file, but no file
is found at that path.
""" | class ConfigDoesNotExistException(CookiecutterException):
'''
Exception for missing config file.
Raised when get_config() is passed a path to a config file, but no file
is found at that path.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 5 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 7 | 1 | 1 | 1 | 0 | 5 | 1 | 1 | 0 | 0 | 4 | 0 | 0 |
15,398 | audreyr/cookiecutter | audreyr_cookiecutter/cookiecutter/exceptions.py | cookiecutter.exceptions.ContextDecodingException | class ContextDecodingException(CookiecutterException):
"""
Exception for failed JSON decoding.
Raised when a project's JSON context file can not be decoded.
""" | class ContextDecodingException(CookiecutterException):
'''
Exception for failed JSON decoding.
Raised when a project's JSON context file can not be decoded.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 4 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 10 | 6 | 1 | 1 | 1 | 0 | 4 | 1 | 1 | 0 | 0 | 4 | 0 | 0 |
15,399 | audreyr/cookiecutter | audreyr_cookiecutter/cookiecutter/exceptions.py | cookiecutter.exceptions.CookiecutterException | class CookiecutterException(Exception):
"""
Base exception class.
All Cookiecutter-specific exceptions should subclass this class.
""" | class CookiecutterException(Exception):
'''
Base exception class.
All Cookiecutter-specific exceptions should subclass this class.
'''
pass | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 4 | 1 | 0 | 0 | 17 | 0 | 0 | 0 | 10 | 6 | 1 | 1 | 1 | 0 | 4 | 1 | 1 | 0 | 0 | 3 | 0 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.