< πŸ’Ž API Reference

WhyΒΆ

class xaiographs.Why(language: str, explainer: Explainer, why_values_semantics: DataFrame, why_target_values_semantics: DataFrame, why_templates: DataFrame | None = None, n_values: int = 2, n_target_values: int = 2, min_reliability: float = 0.0, destination_path: str = './xaioweb_files', verbose: int = 0)ΒΆ

This class is intended to provide an explanation on why a given case has been assigned a certain label (target value), combining case-specific reason (feature-value), model-specific reason (feature-value per target) and the target itself.

Read more in the Reason Why User Guide

Parameters:
  • language (str) –

    Language identifier.

    Important

    Spanish (β€˜es’) and English (β€˜en’) are the available options for version 0.0.2

  • explainer (Explainer) – Object provides an abstract layer which encapsulates everything related to the explanation process from statistics calculation and importance calculation.

  • why_values_semantics (pandas.DataFrame) – Structure containing the natural language explanation of the nodes to be used.

  • why_target_values_semantics (pandas.DataFrame) – Structure containing the natural language explanation of the nodes we want to be used per target value.

  • why_templates (pandas.DataFrame) – Structure containing the templates (following Python template module) of the sentences with the explanation.

  • n_values (int, default=2) – Number of feature-values to take into account for the explanation.

  • n_target_values (int, default=2) – Number of feature-values per target to take into account for the explanation.

  • min_reliability (float, default=0.0) – Minimum reliability value to give an explanation; for the cases with an associated reliability below this value, a default sentence will be provided.

  • destination_path (str, default='./xaioweb_files') – The path where output XAIoWeb files will be stored.

  • verbose (int, default=0) –

    Verbosity level.

    Hint

    Any value greater than 0 means verbosity is on.

Raises:

NameError – Exception when the chosen language is not available.

Methods:

build_semantic_templates(explainer[, ...])

Builds and saves (when requested) the template files for semantic information; the resulting files must be filled up by the user and moved to the corresponding language folder.

fit([sample_id_column, sample_id_value, ...])

Depending on the value of sample_id_value parameter, this method proceeds as follows:

Attributes:

why_explanation

Property that returns the explanation provided by the Why module for either all samples or one of the user's choice.

static build_semantic_templates(explainer: Explainer, destination_template_path: str = './', verbose: int = 0) NoneΒΆ

Builds and saves (when requested) the template files for semantic information; the resulting files must be filled up by the user and moved to the corresponding language folder.

Parameters:
  • explainer (Explainer) – Object provides an abstract layer which encapsulates everything related to the explanation process from statistics calculation and importance calculation. Particularly we need Explainer object to obtain global_target_feature_value_explainability property that contains for each feature value and target pairs, its importance and rank. The rank represents the importance of that feature value pair for the given target value

  • destination_template_path (str) – Path to save both: the element (feature-value) template file and the target template file in CSV format. By default save in relative path.

  • verbose (int, default=0) –

    Verbosity level.

    Hint

    Any value greater than 0 means verbosity is on.

fit(sample_id_column: str = 'id', sample_id_value: Any = None, template_index: str | int = 'rand')ΒΆ

Depending on the value of sample_id_value parameter, this method proceeds as follows:

  • If the mentioned parameter is None then builds a DataFrame with the sentences of the reason why each case has been assigned a label.

  • Otherwise, simply gets the sentence with the reason why a given case has been assigned a label

Parameters:
  • sample_id_column (str, default=ID) – Name of the column that holds the primary key

  • sample_id_value (Any, default=None) – Value to select from the column specified in argument sample_id_column

  • template_index (str or int, default=RAND) –

    Index of the template to be used to build the final sentence amongst the ones available in why_templates attribute; please note that:

    • Index 0 is reserved for the default template.

    • If the requested index is greater than the last available one, the latter will be provided.

Raises:

ValueError – Exception either when the requested key does not exist or when there are more than one row for the requested key.

property why_explanationΒΆ

Property that returns the explanation provided by the Why module for either all samples or one of the user’s choice.

Caution

If the method fit() from the Why class has not been executed, it will return a warning message.

Returns:

why_explanation – Structure containing a column indicating the sample ID and another column containing the verbal explanation

Return type:

pandas.DataFrame

< πŸ’Ž API Reference