Using Stratified Sampling to Improve LIME Image Explanations
-
This repository contains the changes needed to add the stratified sampling strategy to the original codebase of LIME proposed for the Research Article 'Using Stratified Sampling to Improve LIME Image Explanations'. published at Proceedings of the AAAI Conference on Artificial Intelligence.
-
The rest of Experiments for the proposed strategy are uploaded here at LIME Stratified Examples
Installation
The lime_stratified package is on Github, Simply run:
pip install git+https://github.com/rashidrao-pk/lime_stratified.git
Or clone the repository and run:
git clone https://github.com/rashidrao-pk/lime_stratified
cd lime_stratified
python setup.py install
How to use ?
- The class
LimeImageExplaineradds a single parameteruse_stratificationto theexplain_instancemethod. When the parameter is False, the code behaves exactly like the original LIME implementation. Whenuse_stratification=Truethe algorithm StratifiedSampling is used, as described in the paper.
# Code example
from lime_stratified.lime import lime_image
lime_explainer = lime_image.LimeImageExplainer(random_state=1234)
explanation = lime_explainer.explain_instance(image_to_explain,
blackbox_model,
use_stratification=True)
Paper PDF:
Using Stratified Sampling to Improve LIME Image Explanations can be found at LINK and also on
.
Cite
If you use our proposed strategy, please cite us:
@inproceedings{rashid2024using,
title={Using Stratified Sampling to Improve LIME Image Explanations},
author={Rashid, Muhammad and Amparore, Elvio G and Ferrari, Enrico and Verda, Damiano},
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
volume={38},
number={13},
pages={14785--14792},
year={2024}
}
The remaining part of this readme is the original redme file of LIME.
LIME_Stratified
This project is about explaining what machine learning classifiers (or models) are doing. At the moment, we support explaining individual predictions for text classifiers or classifiers that act on tables (numpy arrays of numerical or categorical data) or images, with a package called lime (short for local interpretable model-agnostic explanations based on stratification approach).
LIME_Stratified is based on the work presented in this paper (bibtex here for citation). Here is a link to the promo video:
Our plan is to add more packages that help users understand and interact meaningfully with machine learning.
Lime is able to explain any black box classifier, with two or more classes. All we require is that the classifier implements a function that takes in raw text or a numpy array and outputs a probability for each class. Support for scikit-learn classifiers is built-in.
We dropped python2 support in 0.2.0, 0.1.1.37 was the last version before that.
Tutorials and API
For example usage for text classifiers, take a look at the following two tutorials (generated from ipython notebooks):
For classifiers that use numerical or categorical data, take a look at the following tutorial (this is newer, so please let me know if you find something wrong):
For image classifiers:
For regression:
Submodular Pick:
The raw (non-html) notebooks for these tutorials are available here.
The API reference is available here.
How LIME_Image Works?
Contributing
Please read this.
Metadata
Release files for lime-stratified 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lime_stratified-0.0.1.tar.gz | 277.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lime_stratified-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 564.6 kB
Release files / lime_stratified-0.0.1.tar.gz
| Download URL | lime_stratified-0.0.1.tar.gz |
|---|---|
| Size | 277.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a268ef0ceebffbfc716879e27601b50611d41e450fdccee6a08bc8d8bc300da
|
|
BLAKE2b-256 checksum How to use checksums |
9a17c61e881d461a6ffa7390d781c21efdbea632162b82e272f3265bc108fdc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.18
|
Release files / lime_stratified-0.0.1-py3-none-any.whl
| Download URL | lime_stratified-0.0.1-py3-none-any.whl |
|---|---|
| Size | 287.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
68d35826cac6f9007e7c0ad94e4628882b2b931b4e48d0e70f445a18de0898cc
|
|
BLAKE2b-256 checksum How to use checksums |
92a6a5b68dfe2cce15efb276d69dcda86005c2ee8b153f2e36bcc998b744d9f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.18
|