Generate Explanations
In this section, we show you how to create explanations using the Python Client
Last updated
In this section, we show you how to create explanations using the Python Client
Last updated
Details about how to plot and store the explanations that will be presented in this section, can be found here:
expai.ExpaiModelExplainer
To initialise this class, it is required to get a ModelFairness object using expai.ExpaiProject.get_model_explainer()
. More info here.
expai.ExpaiModelExplainer.get_allowed_explanations
This method returns a ExpaiModelExplainer that enables easy explanation generation.
expai.ExpaiProject.get_allowed_explanations(self)
All following methods will return an ExpaiExplanation object containing the plots used to represent the explanation. See more information here.
expai.ExpaiModelExplainer.explain_model
Explain a model based on a whole dataset or a subset representing some meaningful group for your operations.
expai.ExpaiModelExplainer.explain_model(self, sample_name: str = None, sample_id: str = None, subset_indexes: list = None, target_class: str = None)
subset_indexes
allow you to explain your model based only on a meaningful subgroup in your data. You can use expai.ExpaiProject.get_sample()
to obtain a dataframe, filter and then use the desired indexes.
expai.ExpaiModelExplainer.explain_variable_effect
Explain how a single variable impacts the predictions in your model.
expai.ExpaiModelExplainer.explain_variable_effect(self, sample_name: str = None, sample_id: str = None, subset_indexes: list = None, target_class: str = None, variables: list = None, variables_type: dict = None)
subset_indexes
allow you to explain your model based only on a meaningful subgroup in your data. You can use expai.ExpaiProject.get_sample()
to obtain a dataframe, filter and then use the desired indexes.
expai.ExpaiModelExplainer.explain_sample
Explain how the prediction for a certain sample was made and the importance of each variable.
expai.ExpaiModelExplainer.explain_sample(self, sample_name: str = None, sample_id: str = None, index: int = None, subset_indexes: list = None, target_class: str = None)
If you use subset_indexes,
make sure they contain the index you want to explain.
This module allows you to validate and activate business actions based on your analytical models on the fly.
expai.ExpaiModelExplainer.what_if
Explain how a variable will change the prediction for a single entry when it takes any of its possible values. Obtain a plot for each variable representing the prediction for each possible value when all remaining variables are kept the same.
expai.ExpaiModelExplainer.what_if(self, sample_name: str = None, sample_id: str = None, index: int = None, subset_indexes: list = None, target_class: str = None, variables: list = None, variables_type: dict = None)
subset_indexes
allow you to explain your model based only on a meaningful subgroup in your data. You can use expai.ExpaiProject.get_sample()
to obtain a dataframe, filter and then use the desired indexes.
expai.ExpaiModelExplainer.what_if_battle
With this explanation, you will be able to change the values you want for a single entry and obtain the new prediction and its explanation after the changes. Validate business decisions on the fly.
expai.ExpaiModelExplainer.what_if_battle(self, sample_name: str = None, sample_id: str = None, index: int = None, subset_indexes: list = None, target_class: str = None, replace_dict: dict = None, display_replace_dict: dict = None)
subset_indexes
allow you to explain your model based only on a meaningful subgroup in your data. You can use expai.ExpaiProject.get_sample()
to obtain a dataframe, filter and then use the desired indexes.
Attribute
Description
Required
sample_name
Exact name of the sample that will be used to explain the model.
Yes, if sample_id
is not provided
sample_id
Unique identifier of the sample that will be used to explain the model.
Yes, if sample_name
is not provided
subset_indexes
List containing the indexes that should be considered for the explanation
No
target_class
Name of the class that should be explained
Yes if model is classifier
variables
List of variables that should be explained
Yes
variables_type
Dictionary where variables
are keys and values will represent the type of each variable ('numerical' or 'categorical')
No
Attribute
Description
Required
sample_name
Exact name of the sample that will be used to explain the model.
Yes, if sample_id
is not provided
sample_id
Unique identifier of the sample that will be used to explain the model.
Yes, if sample_name
is not provided
index
Index for the sample that you want to explain
Yes
subset_indexes
List containing the indexes that should be considered for the explanation
No
target_class
Name of the class that should be explained
Yes if model is classifier
Attribute
Description
Required
sample_name
Exact name of the sample that will be used to explain the model.
Yes, if sample_id
is not provided
sample_id
Unique identifier of the sample that will be used to explain the model.
Yes, if sample_name
is not provided
index
Index for the sample that you want to explain
Yes
subset_indexes
List containing the indexes that should be considered for the explanation
No
target_class
Name of the class that should be explained
Yes if model is classifier
variables
List of variables that should be explained
Yes
variables_type
Dictionary where variables
are keys and values will represent the type of each variable ('numerical' or 'categorical')
No
Attribute
Description
Required
sample_name
Exact name of the sample that will be used to explain the model.
Yes, if sample_id
is not provided
sample_id
Unique identifier of the sample that will be used to explain the model.
Yes, if sample_name
is not provided
index
Index for the sample that you want to explain
Yes
subset_indexes
List containing the indexes that should be considered for the explanation
No
target_class
Name of the class that should be explained
Yes if model is classifier
replace_dict
Dictionary where keys contain the name of the variable to be replaced and values are the desired new values.
Yes
display_replace_dict
If you are using display samples, you can also introduce the display value for the replacements.
No
Attribute
Description
Required
sample_name
Exact name of the sample that will be used to explain the model.
Yes, if sample_id
is not provided
sample_id
Unique identifier of the sample that will be used to explain the model.
Yes, if sample_name
is not provided
subset_indexes
List containing the indexes that should be considered for the explanation
No
target_class
Name of the class that should be explained
Yes if model is classifier