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 install the required dependencies and use the package locally:
pip install numpy pandas matplotlib scikit-learn shap
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sequential_shap_explainer-0.1.0.tar.gz.
File metadata
- Download URL: sequential_shap_explainer-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
237c977321fa02a9fb2135ba53b23088de94382b620d871d276b25cf09d4860e
|
|
| MD5 |
e30f5f595e28e9513b7b5870a353e632
|
|
| BLAKE2b-256 |
d72bc94033ff0290cfb56bc0d6c5c29f52897219efacb60016d271643d360ed7
|
File details
Details for the file sequential_shap_explainer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sequential_shap_explainer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b1b254d77b0c1eba69f8800b540c2687a4cdf6b6699bb060ddff9fbadb3ee31
|
|
| MD5 |
0b02d210909c43669d9768f2620e3615
|
|
| BLAKE2b-256 |
628bbf933956b1fac79db63a15ad80cd6ee36092eec9c461132ad8e7acdbe55b
|