# fatf.transparency.predictions.lime.Lime¶

class fatf.transparency.predictions.lime.Lime(data: numpy.ndarray, model: object = None, **kwargs)[source]

A sub-class of the Lime class designated for explaining a prediction.

This class initialises a fatf.transparency.lime.Lime class and overwrites the sample_around_instance/local_explanation to be True, therefore creates a single prediction explainer.

For reference please see the description of the fatf.transparency.lime.Lime class.

Methods

 explain_instance(instance, **kwargs) Explains an instance with the LIME tabular explainer.
explain_instance(instance: numpy.ndarray, **kwargs) → Union[Dict[str, Tuple[str, float]], List[Tuple[str, float]]][source]

Explains an instance with the LIME tabular explainer.

This method wraps around explain_instance method in the LIME tabular explainer object.

Warning

Contrarily to the LIME tabular explainer this wrapper produces explanations for all of the classes for a classification task by default.

If any of the named parameters for this function were specified when initialising this object they will be used unless they are also defined when calling this method, in which case the latter take the precedence.

If all: a class-wide model, a class-wide prediction function and a local prediction function (via named parameter to this function) are specified, they are used in the following order:

• local prediction function,

• global prediction function, and finally

• the model.

Based on whether the task at hand is classification or regression either predict (regression) or predict_proba (classification) method of the model is used.

Parameters
instancenumpy.ndarray

A 1-dimensional data point (numpy array) to be explained.

**kwargslime.lime_tabular.LimeTabularExplainer.explain_instance

LIME tabular explainer’s explain_instance optional parameters.

Returns
explanationDictionary[string, Tuple[string, float]] or List[Tuple[string, float]]

For classification a dictionary where the keys correspond to class names and the values are tuples (string and float), which represent an explanation in terms of one of the features and the importance of this explanation. For regression a list of tuples (string and float) with the same meaning.

Raises
AttributeError

One of the named parameters is invalid for the explain_instance method of the LIME tabular explainer.

IncorrectShapeError

The input instance is not a 1-dimensional numpy array.

RuntimeError

A predictive function is not available (neither as a model attribute of this class, nor as a predict_fn parameter).

ValueError

The input instance is not purely numerical.