explainy.core package

Submodules

explainy.core.explanation module

class explainy.core.explanation.Explanation(score_text, method_text, natural_language_text, separator='\n')[source]

Bases: object

Explanation class

get_explanation(separator='\n')[source]
print_output(separator='\n')[source]

explainy.core.explanation_base module

Created on Tue Nov 24 21:15:30 2020

@author: mauro

class explainy.core.explanation_base.ExplanationBase(model: Union[sklearn.base.ClassifierMixin, sklearn.base.RegressorMixin], config: Dict = None)[source]

Bases: abc.ABC, explainy.core.explanation_mixin.ExplanationMixin

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]

WIP

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: Union[pandas.core.frame.DataFrame, numpy.array]) → 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]

abstract get_feature_values()[source]
get_method_text() → None[source]

Generate the output of the method explanation.

Returns

None

get_model_text() → str[source]

WIP Generate text the explains the used machine learning model

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) → str[source]

Get the name of the plot

Parameters

sample_name (str, optional) – [description]. 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) → 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

get_sentences() → None[source]

Generate the output sentences

Returns

None

importance()[source]
abstract plot()[source]
save(sample_index: int, sample_name: str = 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.

save_csv(sample: int) → None[source]

Save the explanation to a csv. The columns contain the method_text, the natural_language_text, the name of the plot and the predicted value. The index is the Entry ID.

Parameters

sample (TYPE, optional) – DESCRIPTION.

Returns

None.

set_paths() → None[source]

Set the paths where the output should be saved

Returns

None.

setup_logger(logger_name: str) → object[source]

explainy.core.explanation_mixin module

Created on Thu May 13 21:49:43 2021

@author: maurol

class explainy.core.explanation_mixin.ExplanationMixin[source]

Bases: object

get_number_to_string_dict() → None[source]

map number of features to string values

static join_text_with_comma_and_and(values: list) → str[source]

Merge values for text output with commas and only the last value with an “and””

Parameters

values (list) – list of values to be merged.

Returns

new text.

Return type

str

map_category(feature_name, feature_value)[source]
Parameters
  • feature_name (TYPE) – DESCRIPTION.

  • feature_value (TYPE) – DESCRIPTION.

Returns

DESCRIPTION.

Return type

feature_value (TYPE)

Module contents