Link Search Menu Expand Document
PyXAI
Papers Video GitHub In-the-Loop EXPEKCTATION Release Notes About

Explaining Module

The Explaining module provides different methods for explaining decisions made by ML models. The classe Explainer is the main class that common functionality for computing explanations on various machine learning models. All explainers are subclasses of this last one.

The function of module Explaining.initialize returns the appropriate Explainer object according to a model.

Explaining.initialize(model, instance=None, features_type=None) Highlight

Return and initialize an explainer according to a model and optionally an instance and a domain theorie.

Parameters

instance: list[int] (optional, default=None)

The instance (an observation) on which explanations must be calculated.

features_type: dict | str (optional, default=None)

Either a Python dictionnary containing the keys numerical, categorical and binary or the file path of a .types file.
Activate a domain theorie.

Returns

ExplainerDT | ExplainerRF | ExplainerBT | ExplainerRegressionBT:

The appropriate explainer according to model.

Examples

from pyxai import Learning, Explaining, Tools
learner = Learning.Scikitlearn("../../dataset/iris.csv", problem_type=Learning.CLASSIFICATION)
model = learner.evaluate(splitting_method=Learning.HOLD_OUT, model_type=Learning.DT)

instance, prediction = learner.get_instances(model, n=1, is_correct=True)
explainer = Explaining.initialize(model, instance)

Methods

Main Methods

Human-Readable Explanation Methods

Explanation verification methods

 

 

Methods for calculating explanations

 

 

 

Rectification Methods

  • ExplainerDT.rectify: Rectification enforces that the (parsed) conditions imply the given label in the model.
  • ExplainerRF.rectify: Rectify the random forest to satisfy a labeled constraint.

Enumerations

Explaining.ALL

Explaining.ALL: Constant meaning that all explanations are requested

Explaining.TIMEOUT

Explaining.TIMEOUT: Time out has been reached when computing some explanations (see the documentation page)

PreferredReasonMethod

Represent the available methods for a preference criterion in some explanations.

  • PreferredReasonMethod.Minimal | Explaining.MINIMAL | minimal:
    Equivalent to minimal_majoritary_reason().

  • PreferredReasonMethod.FeatureImportance | Explaining.FEATURE_IMPORTANCE | feature-importance:
    The opposite of the f-importance of each feature in F as computed by Scikit-Learn.

  • PreferredReasonMethod.Shapley | Explaining.SHAPLEY | shapley:
    Shapely values for the model trained on data. Only available with a model from scikitlearn or a save from scikitlearn. For each random forest F, the opposite of the SHAP score [Lundberg and Lee, 2017; Lundberg et al., 2020] of each feature of the instance x at hand given F computed using SHAP (shap.readthedocs.io/en/latest/api.html)

  • PreferredReasonMethod.Weights | Explaining.WEIGHTS | weights:
    Weight given bu the user thought the weights parameters.

  • PreferredReasonMethod.WORD_FREQUENCY | Explaining.WordFrequency | word-frequency:
    The opposite of the Zipf frequency of each feature viewed as a word in the wordfreq library.

  • PreferredReasonMethod.WORD_FREQUENCY_LAYERS | Explaining.WordFrequencyLayers | word-frequency-layers:
    WORD_FREQUENCY with layers.

Dictionnaries

ImageDict

This Python Dictionnary contains some information about a learner, a dataset and a model.

  • shape: (int, int) | (int, int, int)
    Tuple representing the number of horizontal and vertical pixels. If the number of values representing a pixel is not equal to 1, the last value of this tuple have to contain this number (example: (8,8,3) represents an image of 8 * 8 = 64 pixels where each pixel contains 3 color values (RGB)).

  • dtype: numpy.dtype Domain of values for each pixel. For example, numpy.uint8 for 256 values from 0 to 255.

  • get_pixel_value(instance, x, y, shape): Callable
    Python function with 4 parameters which returns the value of a pixel according to a pixel position (x,y). Get from the position of a pixel x and y a color value according to an instance.

  • instance_index_to_pixel_position(i, shape): Callable
    Python function with 2 parameters which returns a pixel position (x,y) according to an index of the instance.

Example

TODO

Symbols