explainy.core package#
Submodules#
explainy.core.explanation module#
- class explainy.core.explanation.Explanation(score_text: str, method_text: str, natural_language_text: str, separator: str = '\n')[source]#
Bases:
objectExplanation class
explainy.core.explanation_base module#
- class explainy.core.explanation_base.ExplanationBase(model: ClassifierMixin | RegressorMixin, config: Dict[str, str] | None = None)[source]#
Bases:
ABC- define_explanation_placeholder(natural_language_text_empty: str, method_text_empty: str, sentence_text_empty: str) None[source]#
Set the explanation text, if defined else load it from defaults
- Parameters:
natural_language_text_empty (str) – natural language explanation placeholder
method_text_empty (str) – method placeholder
sentence_text_empty (str) – sentence text placeholder
- get_description_text() str[source]#
Generate the description of the explanation method.
Example
This is a SHAP explanation, it creates local and non-contrastive explanations.
- Returns:
return the explanation method description
- Return type:
str
- get_feature_names(X: DataFrame | ndarray) List[str][source]#
Get the feature names based on the given dataset
- Parameters:
X (Union[pd.DataFrame, np.array]) – features dataset
- Returns:
list of feature names
- Return type:
List[str]
- get_model_text() str[source]#
Generate text the explains the used machine learning model (wip)
- Returns:
return the description of the machine learning model
- Return type:
str
- get_natural_language_text() str[source]#
Generate the output of the explanation in natural language.
- Returns:
return the natural_language_text explanation
- Return type:
str
- get_number_of_features(number_of_features: int) int[source]#
Set the number of features based on the defined number and the max number of features
- Parameters:
number_of_features (int) – number_of_features as input
- Returns:
number_of_features considering the max number of dataset features
- Return type:
int
- get_plot_name(sample_name: str | None = None) str[source]#
Get the name of the plot
- Parameters:
sample_name (str, optional) – name of the sample. Defaults to None.
- Returns:
return the name of the plot
- Return type:
str
- get_prediction(sample_index: int) float[source]#
Get the model prediction
- Parameters:
sample_index (int) – sample_index for a which a predction shall be made
- Returns:
predction of the model for that sample
- Return type:
float
- get_sample_name(sample_index: int, sample_name: str | None = None) str[source]#
Determine the name of the sample, if no sample_name provide, use the sample_index
- Parameters:
sample_index (int) – index of the sample
sample_name (str, optional) – name of the sample. Defaults to None.
- Returns:
name of the sample
- Return type:
str
- get_score_text() str[source]#
Generate the text explaining the prediction score of the sample
- Returns:
return the score_text for the sample.
- Return type:
str
- save(sample_index: int, sample_name: str | None = None) None[source]#
Save the explanations to a csv file, save the plots
- Parameters:
sample_index (int) – [description]
sample_name (str, optional) – name of the sample. Defaults to None.