Spaces:
Sleeping
Sleeping
APP_INTRODUCTION = """ | |
This application provides an **Explainable AI (XAI)** framework to analyze a machine learning model trained on the **UCI Adult Income Dataset** ([link](https://archive.ics.uci.edu/dataset/2/adult)). The model predicts whether an individual earns more than **$50,000 per year** based on key demographic and employment-related features, including: | |
- **Age** | |
- **Education Level** | |
- **Marital Status** | |
- **Sex (Gender)** | |
- **Occupation, Work Hours, Country**, etc. | |
To ensure transparency and interpretability, the app utilizes multiple **XAI techniques** to explain model predictions: | |
### **Explainability Methods** | |
1. **ALE (Accumulated Local Effects)** – Measures feature influence while considering feature dependencies. | |
2. **Anchors** – Provides high-precision rule-based explanations for individual predictions. | |
3. **ICE & PDP (Individual Conditional Expectation & Partial Dependence Plots)** – Visualizes how a feature affects the model prediction globally and individually. | |
4. **LIME (Local Interpretable Model-agnostic Explanations)** – Generates local approximations to explain specific predictions. | |
5. **Permutation Feature Importance** – Assesses the importance of features by measuring the change in prediction error after shuffling feature values. | |
6. **SHAP (SHapley Additive exPlanations)** – Computes fair feature attributions based on cooperative game theory. | |
""" | |
LIME_INTRODUCTION = """ | |
LIME (Local Interpretable Model-agnostic Explanations) is a technique used to interpret the predictions of black-box machine learning models. | |
It provides local interpretability by approximating the decision boundary of the model in the vicinity of a specific instance with a simpler, interpretable model. | |
The working principle of LIME includes the following steps: | |
1. Select the instance to explain. | |
2. Generate perturbed samples by randomly altering feature values to create similar data points. | |
3. Obtain model predictions for these perturbed samples using the original black-box model. | |
4. Compute similarity weights by assigning higher weights to samples more similar to the original instance. | |
5. Train a local interpretable model (usually a weighted linear regression model). | |
6. Interpret the results by analyzing the coefficients of the local model to understand feature contributions to the prediction. | |
By using LIME, complex models become more transparent, enhancing their trustworthiness and interpretability. | |
""" | |
LIME_KERNEL_WIDTH_HELP = """ | |
The `kernel_width` parameter in LIME controls the size of the neighborhood used to generate perturbations around a sample | |
for explanation. It determines how far the generated synthetic data points will be from the original instance. | |
### How It Works: | |
- **Smaller Values (e.g., 1.0 - 3.0):** Focus on very local explanations, meaning LIME will give more weight to points closer to the original sample. | |
- **Larger Values (e.g., 10.0 - 100.0):** Expand the neighborhood, leading to more global explanations that consider a broader range of feature values. | |
### Recommended Settings: | |
- **For simple models or small datasets:** Start with `kernel_width = 3.0`. | |
- **For complex models or high-dimensional data:** A larger value (e.g., `10.0 - 25.0`) may provide better stability. | |
- **For debugging or fine-tuning:** Experiment with different values to see how it impacts feature importance rankings. | |
⚠️ **Note:** A very large `kernel_width` can make explanations less interpretable, as it may include too many outliers. | |
""" | |
EXAMPLE_BE_EXPLAINED_IDX=""" | |
Select the index of the example you want to explain. | |
e.g., Example 100 is higher than 50K | |
""" | |
ANCHORS_INTRODUCTION = """ | |
Anchors provide model-agnostic interpretations similar to LIME but aim to generate highly **precise and human-interpretable rules** that sufficiently explain the model’s prediction for a given instance. | |
The process of Anchors includes the following steps: | |
1. Select the instance to explain. | |
2. Generate perturbed samples but modify only **non-anchor** features while keeping others fixed. | |
3. Get model predictions for these perturbed samples. | |
4. Find **stable anchor conditions** that ensure the perturbed samples consistently receive the same prediction as the original instance. | |
5. Trade-off between precision and coverage: | |
- **Precision**: The fraction of perturbed samples that match the original prediction under the anchor rule. | |
- **Coverage**: The fraction of all possible perturbations that the anchor rule applies to. | |
6. Final explanation is presented as an **if-then rule**, making it highly interpretable. | |
By using Anchors, interpretability improves by generating highly stable and human-readable explanations, making them particularly useful for high-stakes applications. | |
""" | |
ANCHORS_THRESHOLD_HELP = """ | |
The `threshold` parameter controls the precision (confidence) level of the Anchor rule. | |
- It defines the **minimum confidence** required for an Anchor rule to be considered valid. | |
- The typical range is **0.8 to 0.95**: | |
- Lower values (e.g., 0.7) allow more flexible rules but may include some noise. | |
- Higher values (e.g., 0.95) ensure highly reliable rules but make them harder to find. | |
- If set to **1.0**, only rules with 100% confidence will be accepted, which may result in no valid rules being found. | |
Choosing an appropriate threshold balances **rule reliability** and **availability**. | |
""" | |
SHAP_INTRODUCTION = """ | |
SHAP (SHapley Additive exPlanations) provides model-agnostic interpretations to fairly distribute the contribution of each feature to a model's prediction. | |
The process of SHAP includes the following steps: | |
1. **Train a Model**: Fit a machine learning model (e.g., XGBoost) on a dataset. | |
2. **Select Baseline Data**: Choose a reference point (average prediction) to compute feature contributions. | |
3. **Compute SHAP Values**: Quantify the contribution of each feature using a weighted average over all possible feature subsets. | |
4. **Ensure Additivity**: The sum of SHAP values should match the model's prediction difference from the baseline. | |
By using SHAP, **interpretability** improves by generating stable and mathematically sound explanations, making models more transparent and trustworthy. | |
""" | |
ICE_INTRODUCTION = """ | |
Individual Conditional Expectation (ICE) plots provide a more granular view of feature influence by displaying the response of each individual instance to changes in a selected feature, rather than averaging across all instances as in Partial Dependence Plots (PDP). | |
The process of ICE includes the following steps: | |
1. **Select the Feature of Interest**: Choose a variable to analyze, such as Age. | |
2. **Create a Feature Grid**: Define a range of values for the chosen feature (e.g., Age from 20 to 80). | |
3. **Iterate Over Each Instance**: For each sample, replace the feature with values from the grid while keeping all other features unchanged. | |
4. **Compute Predictions**: Use the trained model to predict outcomes for each modified sample and store the predictions. | |
5. **Plot Individual Curves**: Each sample produces a separate curve, representing how its prediction evolves as the feature changes. | |
By using ICE, **interpretability** improves by showing how a feature influences predictions at an individual level, capturing heterogeneous effects that PDP might average out. | |
A Partial Dependence Plot (PDP) illustrates the marginal effect of a selected feature on the model’s predictions while averaging out the influence of all other features. | |
The process of PDP includes the following steps: | |
1. **Select the Feature of Interest**: Choose a variable for PDP analysis, such as Age. | |
2. **Create a Feature Grid**: Define a range of values for the selected feature (e.g., Age from 20 to 80). | |
3. **Modify the Dataset and Compute Predictions**: For each value in the grid, replace the feature value in all instances while keeping other features unchanged. Use the trained model to predict outcomes for the modified dataset. | |
4. **Compute the Average Prediction**: Aggregate predictions across all instances and calculate the mean for each feature value in the grid. | |
By using PDP, **interpretability** improves by showing the average effect of a feature on model predictions, making complex models more explainable. | |
When `kind` is selected: | |
- **both**: Displays both ICE and PDP. | |
- **individual**: Displays only ICE. | |
- **average**: Displays only PDP. | |
""" | |
ALE_INTRODUCTION = """ | |
ALE (Accumulated Local Effects) is an interpretable machine learning technique that quantifies the impact of a feature on model predictions while accounting for feature dependencies. | |
The process of ALE includes the following steps: | |
1. **Bin the Feature**: Divide the feature into intervals (bins) to segment the data. | |
2. **Compute Local Effects**: Measure the change in predictions when the feature moves from the lower to the upper edge of each bin. | |
3. **Accumulate Effects**: Sum the local effects sequentially across bins to observe the overall influence of the feature. | |
4. **Centering**: Normalize the accumulated effects by subtracting the mean to focus on relative deviations from the average prediction. | |
By using ALE, **interpretability** improves by capturing localized effects while mitigating bias from correlated features, making model explanations more reliable. | |
""" | |
PERMUTATION_INTRODUCTION = """ | |
Permutation Feature Importance is an interpretable machine learning technique that evaluates feature importance by measuring the impact of shuffling a feature’s values on model error. | |
The process of Permutation Feature Importance includes the following steps: | |
1. **Compute Initial Model Error**: Measure the model’s baseline performance using a metric like Mean Squared Error (MSE). | |
2. **Permute a Feature**: Randomly shuffle the values of a selected feature while keeping all other features unchanged. | |
3. **Compute New Model Error**: Re-evaluate the model on the dataset with the shuffled feature to obtain a new error score. | |
4. **Calculate Feature Importance**: Compute the difference between the new error and the original error. A larger difference indicates higher importance. | |
5. **Repeat for Stability**: Perform multiple repetitions of permutation and calculate the mean and standard deviation of feature importance scores for reliability. | |
By using Permutation Feature Importance, **interpretability** improves by providing a direct measure of a feature’s contribution to predictive performance, making model explanations more intuitive and robust. | |
""" | |