Skip to main content

An innovative approach to improve the interpretability of the SHAP method for sequential multi-class classification.

Project description

Sequential SHAP

In this study, the limitations of the SHAP (Shapley Additive exPlanations) method have been examined within the scope of Explainable Artificial Intelligence (XAI), particularly regarding sequential multi-class classification problems.

Stemming from the observation that the classical SHAP method is restricted to revealing only positive and negative contributions for a single class, a modified alternative approach is proposed to overcome these constraints. This novel method aims to elucidate the model's decision-making mechanism in a more granular manner by categorizing feature effects into distinct semantic groups.

The Sequential Solution

Sequential SHAP addresses standard SHAP restrictions by breaking down the multi-class problem into two distinct binary classification stages based on a provided semantic class hierarchy (order). It categorizes features into three distinct groups:

  • UPPER (Red): Features driving the prediction towards a higher class.
  • LOWER (Blue): Features driving the prediction towards a lower class.
  • AMBIGUOUS (Gray): Features demonstrating inconsistent or uninformative effects across class transitions.

The findings obtained from analyses—such as on an obesity dataset—indicate that this proposed approach offers more profound insights than standard SHAP analysis and enables precise interpretations regarding class transitions. In conclusion, this modification significantly enhances the transparency of the model, presenting a robust analytical framework for complex hierarchical classification scenarios where interpretability is critically important.

Installation

You can easily install the package via pip:

pip install sequential-shap-explainer

Note: The current version is optimized for tree-based models (e.g. Random Forest) and uses shap.TreeExplainer under the hood.

Usage Example

from sequential_shap import SequentialSHAP

# 1. Initialize the explainer with your trained model, training data, and the semantic order of your classes
# Example: class_order=['Low', 'Medium', 'High']
explainer = SequentialSHAP(
    model=your_trained_model,
    X_train=X_train,
    y_train=y_train,
    class_order=['Low_Level', 'Medium_Level', 'High_Level'] 
)

# 2. Explain a specific instance by its index in the dataset
results_df = explainer.explain_by_index(index=42)

# 3. View the summarized DataFrame
print(results_df)

# 4. Plot the Sequential SHAP chart
explainer.plot()

Technical Features

  • Automatic String Label Conversion: Safely maps string class labels to internal integers.
  • Custom DataFrame Output: Embeds the primary prediction into the DataFrame string representation for cleaner console readability.
  • Intuitive Visualization: Automatically sorts and colors features based on their true directional impact on sequential classes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sequential_shap_explainer-0.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sequential_shap_explainer-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file sequential_shap_explainer-0.1.1.tar.gz.

File metadata

File hashes

Hashes for sequential_shap_explainer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fe0c289a817f5625c8a1000a264fba4e679307c8fecb60ad0fd0bf4513fe1889
MD5 adf4f25718ed261258fdc4f838aaf5bb
BLAKE2b-256 2f614975aadfbf76f21e0a44ffc84affecd85816f8d7a9ff6c8e70944177b0b6

See more details on using hashes here.

File details

Details for the file sequential_shap_explainer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sequential_shap_explainer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0df86d6d7fe134982cb320957fe93e5dc3da40744a77f5be2ca18abb94e5552
MD5 4a93386b9dd6276e33fcf6cb2b1124e7
BLAKE2b-256 ec3b2416e6d19062e4bfd91666c667fae15ec6dba45af07cd2d1c11332d6d0b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page