trustyai.explainers.LimeExplainer
- class trustyai.explainers.LimeExplainer(**kwargs)
“Which features were most important to the results?”
LIME (Local Interpretable Model-agnostic Explanations) seeks to answer this question via providing saliencies, weights associated with each input feature that describe how strongly said feature contributed to the model’s output.
- __init__(**kwargs)
Initialize the
LimeExplainer.- Parameters:
- Keyword Arguments:
- penalise_sparse_balancebool
(default=
True) Whether to penalise features that are likely to produce linearly inseparable outputs. This can improve the efficacy and interpretability of the outputted saliencies.
- normalise_weightsbool
(default=
False) Whether to normalise the saliencies generated by LIME. If selected, saliencies will be normalized between 0 and 1.
- use_wlr_modelbool
(default=
True) Whether to use a weighted linear regression as the LIME explanatory model. If false, a multilayer perceptron is used, which generally has a slower runtime,
- seed: int
(default=
0) The random seed to be used.
- perturbations: int
(default=
1) The starting number of feature perturbations within the explanation process.
- trackCounterfactualsbool
(default=
False) Keep track of produced byproduct counterfactuals during LIME run.
- samples: int
(default=
300) Number of samples to be generated for the local linear model training.
- encoding_params: Union[list, tuple]
(default=
(0.07, 0.3)) Lime encoding parameters, as a tuple/list of two float numbers: - encoding_params[0] is the width of the Gaussian filter for clustering number features. - encoding_params[1] is the threshold for clustering number features.
- data_distribution: PredictionInputsDataDistribution
(default=
PredictionInputsDataDistribution([])) Data distribution used to find better feature perturbations
- features: int
(default=
6) Number of feature to select from the original set of input features
- retries: int
(default=
3) Number of retries performed by LIME to find a separable dataset
- dataset_minimum: int
(default=
10) Minimum number of samples retained by the proximity filter to be acceptable
- separable_dataset_ratio: float
(default=
0.1) Minimum portion of the encoded dataset that needs to have a different label
- kernel_width: float
(default=
0.5) Width of the proximity kernel
- proximity_threshold: float
(default=
0.83) Proximity threshold used to retain close samples
- adapt_dataset_variance: bool
(default=
True) Whether LIME should try to increase the perturbation variance in subsequent retries
- feature_selection: bool
(default=
True) Whether LIME should generate saliency for to the most important features only
- filter_interpretable: bool
(default=
False) Whether the proximity filter should happen in the interpretable space
Methods
__init__(**kwargs)Initialize the
LimeExplainer.explain(inputs, outputs, model)Produce a LIME explanation.
- explain(inputs: int | float | integer | inexact | ndarray | DataFrame | Series | List[Feature] | PredictionInput, outputs: int | float | integer | inexact | ndarray | DataFrame | Series | List[Output] | PredictionOutput, model: PredictionProvider | Model) LimeResults
Produce a LIME explanation.
- Parameters:
- inputsint, float,
numpy.number, List[Union[int, float,numpy.number]],numpy.ndarray,pandas.DataFrame,pandas.Series, List[Feature], orPredictionInput The input features to the model, as a:
If there’s only a single input feature, an
int,float, or any of the Numpy equivalents can be used.A list of
int,float, or any of the Numpy equivalents.Numpy array of shape
[1, n_features]or[n_features]Pandas DataFrame with 1 row and
n_featurescolumnsPandas Series with n_features rows
A List of TrustyAI
Feature, as created by thefeature()functionA TrustyAI
PredictionInput
- outputsint, float,
numpy.number, List[Union[int, float,numpy.number]],numpy.ndarray,pandas.DataFrame,pandas.Series, List[Output], orPredictionOutput The corresponding model outputs for the provided features, that is,
outputs = model(input_features). These can take the form of a:If there’s only a single output, an
int,float, or any of the Numpy equivalents can be used.A list of
int,float, or any of the Numpy equivalents.Numpy array of shape
[1, n_outputs]or[n_outputs]Pandas DataFrame with 1 row and
n_outputscolumnsPandas Series with n_outputs rows
A List of TrustyAI
Output, as created by theoutput()functionA TrustyAI
PredictionOutput
- model
PredictionProvider The TrustyAI PredictionProvider, as generated by
ModelorArrowModel.
- inputsint, float,
- Returns:
LimeResultsObject containing the results of the LIME explanation.