A model explainability toolkit with SHAP, LIME, scoring, summaries, and GUI sandbox
Project description
Model Explain
model_explain is a Python package for interpreting and explaining machine learning models. It provides a unified interface for popular explanation techniques, including LIME, SHAP, and Grad-CAM and supports a wide range of models and data types.
Key Features
- Unified API for LIME and SHAP explanations
- Model-agnostic: works with any model supporting
predictorpredict_proba - Tabular, image, and text data support
- Visualizations for both local and global explanations
- Easy integration with scikit-learn, XGBoost, LightGBM, and more
- Feature importance extraction and plotting
- Interpretability for individual predictions and datasets
Installation
Install from PyPI:
pip install model-explain
Or, if you prefer to clone the repository and install manually:
git clone https://github.com/vaibhav-k/model_explain.git
cd model_explain
pip install .
Quick Start
Tabular Data Example (LIME)
from model_explain.explainers.lime_explainer import lime_explainer
# model: trained scikit-learn model
# X_test: pandas DataFrame of test features
explanation = lime_explainer(model, X_test, instance_index=0)
explanation.show_in_notebook()
Tabular Data Example (SHAP)
import shap
from model_explain.explainers.shap_explainer import shap_explainer
# model: trained machine learning model
# X_test: pandas DataFrame of test features
shap_values = shap_explainer(model, X_test)
shap.summary_plot(shap_values, X_test)
Image Data Example
from model_explain.explainers.grad_cam import GradCAM
import matplotlib.pyplot as plt
# model: your trained CNN model (e.g., from torchvision)
# image: a preprocessed image tensor of shape [1, C, H, W]
# predicted_class: integer index of the predicted class
explainer = GradCAM(model, target_layer_name="layer4") # specify the last conv layer
heatmap = explainer(image, target_idx=predicted_class)
plt.imshow(heatmap, cmap="jet", alpha=0.5)
plt.title("Grad-CAM Heatmap")
plt.axis("off")
plt.show()
Supported Models
- Scikit-learn models
- XGBoost
- LightGBM
- PyTorch models
- Any model with
predictorpredict_probamethods
Visualizations
- SHAP summary plot: global feature importance (use plot_feature_importance for custom bar plots)
- LIME explanation plot: local feature contributions (use plot_feature_importance for instance-level contributions)
- Image region importance (Grad-CAM heatmap): highlights spatial regions in images that most influence the model's prediction
Use Cases
- Debugging and validating ML models
- Regulatory compliance and transparency
- Feature selection and engineering
- Enhancing trust in AI systems
- Explaining model predictions to stakeholders
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for details on how to contribute.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 model_explain-0.3.0.tar.gz.
File metadata
- Download URL: model_explain-0.3.0.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f9ed96b4bc59c051374c612ce18cb9befbda9dac6f98c6709e8071e95030d96
|
|
| MD5 |
79632c6824ba8ea31ac95c2ae5eff738
|
|
| BLAKE2b-256 |
9b65d88f517521e25326197f52c7f5942c42c4cb98d12599425d18da33e25348
|
File details
Details for the file model_explain-0.3.0-py3-none-any.whl.
File metadata
- Download URL: model_explain-0.3.0-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6769a731c7fe4691d1ea5d4391020808f0e085524f742364dbbe0d5e5166f40c
|
|
| MD5 |
e46d8d051841472a2bbf8d7e7506dd59
|
|
| BLAKE2b-256 |
5f89ee1dd8197400c0dcf2748d3417637b6d7e5d9166bf9dfc4c54f36604bfc7
|