Alibi Documentation

repository·master·Indexed 25 days ago

https://github.com/seldonio/alibi

A Python library for machine learning model inspection and interpretation. Alibi provides implementations of black-box, white-box, local, and global explanation methods for classification and regression models, including ALE, Anchors, Integrated Gradients, and SHAP. It also includes modules for assessing model confidence via Trust Scores and finding representative dataset instances using ProtoSelect.

Tokens
104.8K
Snippets
172
Records
590
Agent score
81%

What's inside Alibi

  1. Overview of the Anchors algorithm

    master

    The Anchors algorithm provides model-agnostic, high-precision, human-interpretable explanations for classification models applied to text, tabular, and image data. Unlike LIME, which uses linear proxies, Anchors find 'if-then' rules (anchors) that are locally sufficient to guarantee a prediction with high confidence.

    Key concepts:

    • Precision: The probability that the model returns the same label for other instances satisfying the anchor predicates. The user specifies a threshold for this.
    • Coverage: The proportion of the population that satisfies the anchor predicates.
    • Rule: A set of predicates connected by AND (e.g., Age < 30 AND Occupation = Engineer).
  2. Overview of Alibi Explain

    master

    Alibi Explain is a source-available Python library designed for machine learning model inspection and interpretation. It provides high-quality implementations of various explanation methods, including:

    • Black-box methods: Explaining models without access to internal parameters.
    • White-box methods: Explaining models using internal knowledge (e.g., gradients).
    • Local explanations: Explaining individual predictions.
    • Global explanations: Explaining the overall behavior of the model.
    • Supported tasks: Both classification and regression models.
  3. Overview of Model Explanation algorithms

    master

    Alibi provides various algorithms for explaining machine learning model predictions. These are categorized into two main types:

    1. Model Explanations (Local): These provide instance-specific explanations, answering "Why did my model make this specific prediction?". Many of these work with black-box (BB) models, requiring only a prediction function (e.g., an API endpoint).
    2. Global Explanations: These explain the model's behavior with respect to an entire dataset rather than a single instance.

    Algorithm Capabilities Summary

    MethodModel TypeExplanation TypeSupported Data/Tasks
    ALEBBGlobalTabular (Numerical)
    Partial DependenceBB, WBGlobalTabular (Num/Cat), Class/Reg
    PD VarianceBB, WBGlobalTabular (Num/Cat), Class/Reg
    Permutation ImportanceBBGlobalTabular (Num/Cat), Class/Reg
    AnchorsBBLocalTabular, Text, Image, Class
    CEMBB* (Differentiable), TF/KerasLocalTabular, Image, Class
    CounterfactualsBB* (Differentiable), TF/KerasLocalTabular, Image, Class
    Prototype CounterfactualsBB* (Differentiable), TF/KerasLocalTabular, Image, Class
    Counterfactuals with RLBBLocalTabular, Image, Class
    Integrated GradientsTF/KerasLocalTabular, Text, Image, Class/Reg
    Kernel SHAPBBLocal & GlobalTabular (Num/Cat), Class/Reg
    Tree SHAPWBLocal & GlobalTabular (Num/Cat), Class/Reg
    Similarity explanationsWBLocalTabular, Text, Image, Class/Reg

    Key Definitions:

    • BB: Black-box (requires only a prediction function).
    • BB*: Black-box, but assumes the model is differentiable.
    • WB: White-box (requires internal model access; e.g., scikit-learn or specific architectures).
    • TF/Keras: Specifically for TensorFlow models via the Keras API.
    • Local: Instance-specific explanation.
    • Global: Explains the model across a dataset.
  4. Understand Counterfactual Explanations

    master

    Counterfactuals are local explanations that identify the minimal changes required to an input instance to achieve a different model prediction. They are used to debug model functionality or provide actionable insights (e.g., how a customer could change their behavior to receive a different financial decision).

    Alibi provides four main methods for generating counterfactuals:

    1. Counterfactual Instances (CFI): Finds minimal changes via gradient descent. Fast fit, slow explain. Best for simple tabular or grayscale image data.
    2. Contrastive Explanation Method (CEM): Uses an elastic net regularizer and an autoencoder to ensure counterfactuals are sparse and stay within the data distribution.
    3. Counterfactuals Guided by Prototypes (CFP): Similar to CEM, uses an autoencoder to ensure the counterfactual is in-distribution.
    4. Counterfactuals with Reinforcement Learning (CFRL): Trains a model via reinforcement learning to generate counterfactuals on demand. Slow fit, fast explain. This is the preferred method for multi-channel images and production environments requiring high performance.
  5. Distinguish between Local and Global insights

    master

    Insights provided by Alibi are categorized by their scope:

    • Local insights: Provide information about a single prediction. For example, identifying which pixels in a specific image caused a classification.
    • Global insights: Provide information about the model's behavior over a range of inputs. For example, showing how a regression prediction varies across the entire range of a specific feature.
  6. Use Permutation Importance for Global Feature Importance

    master

    Alibi provides Permutation Importance to measure global feature importance by calculating the degree of model performance degradation when feature values in a column are permuted.

    Use Case: Identifying which features are most important globally for Tabular data (numerical and categorical) in Classification or Regression tasks.

    Pros:

    • Simple interpretation: importance is the change in model loss/score when a feature is turned into noise.
    • Black-box algorithm.
    • Accounts for all feature interactions.
    • Does not require model retraining.

    Cons:

    • Requires ground truth labels.
    • Can be biased towards unrealistic data instances.
    • Importance metric is tied to the specific loss/score function used.
    • Note: The importance of correlated features can be split between them.
  7. Explore Alibi Overview and Getting Started

    master
    The Alibi library provides tools for machine learning model explanations, model confidence measurement, and prototype selection. You can find high-level introductions, getting started guides, and algorithm overviews in the documentation to understand how to apply different explanation methods to your models.
  8. Measure model confidence with Model Confidence algorithms

    master

    Alibi provides algorithms to generate instance-specific scores that measure how confident a model is in its specific prediction.

    Supported methods:

    • Trust Scores: Produces a score representing the ratio between the distance to the nearest class different from the predicted class and the distance to the predicted class. Higher scores indicate more trustworthy predictions.

      • Supported Models: Black-box (BB)
      • Tasks: Classification
      • Data Types: Tabular, Text, Images
      • Requirement: Training set required
    • Linearity Measure: Produces a score quantifying how linear the model behaves around a specific test instance. It works by feeding the model linear superpositions of inputs and comparing the outputs against the linear combination of outputs from single-input predictions.

      • Supported Models: Black-box (BB)
      • Tasks: Classification, Regression
      • Data Types: Tabular, Images
      • Requirement: Training set optional
  9. Understand Similarity Explanations

    master

    Similarity explanations are instance-based local explanations. They justify a model's prediction by identifying the most similar instances in the training set that share the same prediction.

    Key Characteristics:

    • Scope: Local explanation.
    • Model Types: White-box.
    • Task Types: Classification and Regression.
    • Data Types: Tabular (numerical, categorical), Text, and Image.
    • Use Case: "I classify this image as a 'Golden Retriever' because it is most similar to images in the training set which I also classified as 'Golden Retriever'."