LimeExplainer
LimeExplainer one of the off-the-shelf avaiable explainers in Astrapia. It is a wrapper around lime.
- class astrapia.explainers.LimeExplainer(data, predict_fn, discretize_continuous=True)
Implementation of the Lime Explainer onto the base Explainer class
- __init__(data, predict_fn, discretize_continuous=True)
Initializes a Lime explainer
- Parameters:
data – data that is supposed to be explained
predict_fn – classification model that is supposed to be explained
discretize_continuous – should continuous values be separated into discrete categories
- explain_instance(instance, num_features=10)
Creates a dlime explanation based on a given instance
- Parameters:
instance – instance as dataframe
num_features – amount of features in the dataset
- Returns:
the explanation
- inverse_transform_dataset(data: DataFrame, meta: Dataset)
Inverse transform an explainer-specific dataset into the general Astrapia Dataset format
- Parameters:
data – pandas dataframe holding data in the shape LIME needs it
meta – Astrapia Dataset object holding meta information that does not depend on data instances
- Returns:
pandas dataframe in Astrapia Dataset format
- predict_instance_surrogate(instance)
Helper function for accessing the predictions of lime’s surrogate model
- Parameters:
instance – instance whose prediction should be provided
- Returns:
label prediction of given instance