Skip to content

rashidrao-pk/lime_stratified

 
 

Repository files navigation

Using Stratified Sampling to Improve LIME Image Explanations

Pypi version Python versions Documentation Build status Coverage Code quality License

Installation

The lime_stratified package is on PyPI, Simply run:

pip install lime_stratified

alternatively, it can also be installed using:

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?

Documentation

Contributing

Please read this.

About

Branch of LIME adding stratified Sampling

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 81.0%
  • Python 10.9%
  • HTML 7.1%
  • CSS 1.0%
  • Batchfile 0.0%
  • Makefile 0.0%