Skip to main content

Using Stratified Sampling to Improve LIME Image Explanations

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 LimeImageExplainer adds a single parameter use_stratification to the explain_instance method. When the parameter is False, the code behaves exactly like the original LIME implementation. When use_stratification=True the 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

Binder

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:

KDD 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)

Source distribution for lime-stratified 0.0.1
File Size Uploaded
lime_stratified-0.0.1.tar.gz 277.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lime-stratified 0.0.1
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page