Skip to main content

Using Stratified Sampling to Improve LIME Image Explanations

Project description

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.

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

lime_stratified-0.0.1.tar.gz (277.2 kB view details)

Uploaded Source

Built Distribution

lime_stratified-0.0.1-py3-none-any.whl (287.4 kB view details)

Uploaded Python 3

File details

Details for the file lime_stratified-0.0.1.tar.gz.

File metadata

  • Download URL: lime_stratified-0.0.1.tar.gz
  • Upload date:
  • Size: 277.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for lime_stratified-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0a268ef0ceebffbfc716879e27601b50611d41e450fdccee6a08bc8d8bc300da
MD5 e35a87930c453971f58c5efb8cb09936
BLAKE2b-256 9a17c61e881d461a6ffa7390d781c21efdbea632162b82e272f3265bc108fdc2

See more details on using hashes here.

File details

Details for the file lime_stratified-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for lime_stratified-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68d35826cac6f9007e7c0ad94e4628882b2b931b4e48d0e70f445a18de0898cc
MD5 c42732e32a5d215da2142268603f73ff
BLAKE2b-256 92a6a5b68dfe2cce15efb276d69dcda86005c2ee8b153f2e36bcc998b744d9f5

See more details on using hashes here.

Supported by

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