-
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
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
- The class
LimeImageExplainer
adds a single parameteruse_stratification
to theexplain_instance
method. When the parameter is False, the code behaves exactly like the original LIME implementation. Whenuse_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)
Using Stratified Sampling to Improve LIME Image Explanations can be found at LINK and also on .
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.
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.
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.
Documentation
Please read this.