lemon-explainer-research-use


Namelemon-explainer-research-use JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
Summarylemon-explainer package updated for research usages.
upload_time2024-06-15 08:14:37
maintainerMohammad Amin Dadgar
docs_urlNone
authorDennis Collaris
requires_pythonNone
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img width="250" src="https://explaining.ml/images/lemon-logo.png" />

[![PyPI version](https://badge.fury.io/py/lemon_explainer.svg)](https://badge.fury.io/py/lemon_explainer)

**LEMON** is a technique to explain why predictions of machine learning models are made. It does so by providing feature contribution: a score for each feature that indicates how much it contributed to the final prediction. More precisely, it shows the sensitivity of the feature: a small change in an important feature's value results in a relatively large change in prediction. It is similar to the popular [LIME](https://github.com/marcotcr/lime) explanation technique, but is more faithful to the reference model, especially for larger datasets. 

[Website ↗](https://explaining.ml/lemon)
[Academic paper ↗](https://link.springer.com/chapter/10.1007/978-3-031-30047-9_7)


## Installation

To install use pip:

```
$ pip install lemon-explainer
```

## Example
A minimal working example is shown below:

```python
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from lemon import LemonExplainer

# Load dataset
data = load_iris(as_frame=True)
X = data.data
y = pd.Series(np.array(data.target_names)[data.target])

# Train complex model
clf = RandomForestClassifier()
clf.fit(X, y)

# Explain instance
explainer = LemonExplainer(X, radius_max=0.5)
instance = X.iloc[-1, :]
explanation = explainer.explain_instance(instance, clf.predict_proba)[0]
explanation.show_in_notebook()
```

## Development

For a development installation (requires npm or yarn),

```
$ git clone https://github.com/iamDecode/lemon.git
$ cd lemon
```

You may want to (create and) activate a virtual environment:

```
$ python3 -m venv venv
$ source venv/bin/activate
```

Install requirements:

```
$ pip install -r requirements.txt
```

And run the tests with:

```
$ pytest .
```

## Approximate distance kernel LIME

If you prefer to use a Gaussian distance kernel as used in LIME, we can approximate this behavior with:

```python
from lemon import LemonExplainer, gaussian_kernel
from scipy.special import gammainccinv

DIMENSIONS = X.shape[1]
KERNEL_SIZE = np.sqrt(DIMENSIONS) * .75  # kernel size as used in LIME

# Obtain a distance kernel very close to LIME's gaussian kernel, see the paper for details.
p = 0.999
radius = KERNEL_SIZE * np.sqrt(2 * gammainccinv(DIMENSIONS / 2, (1 - p)))
kernel = lambda x: gaussian_kernel(x, KERNEL_SIZE)

explainer = LemonExplainer(X, distance_kernel=kernel, radius_max=radius)
```

This behavior is as close as possible to LIME, but still yields more faithful explanations due to LEMON's improved sampling technique. Read the paper for more details about this approach.

## Citation

If you want to refer to our explanation technique, please cite our paper using the following BibTeX entry:

```bibtex
@inproceedings{collaris2023lemon,
  title={{LEMON}: Alternative Sampling for More Faithful Explanation Through Local Surrogate Models},
  author={Collaris, Dennis and Gajane, Pratik and Jorritsma, Joost and van Wijk, Jarke J and Pechenizkiy, Mykola},
  booktitle={Advances in Intelligent Data Analysis XXI: 21st International Symposium on Intelligent Data Analysis (IDA 2023)},
  pages={77--90},
  year={2023},
  organization={Springer}
}
```

## License

This project is licensed under the BSD 2-Clause License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "lemon-explainer-research-use",
    "maintainer": "Mohammad Amin Dadgar",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "dadgaramin96@gmail.com",
    "keywords": null,
    "author": "Dennis Collaris",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/9d/b8/39f447590728ab86656d494639dbab4b172e681d5c7b16197dc09206f6a8/lemon-explainer-research-use-1.0.0.tar.gz",
    "platform": null,
    "description": "<img width=\"250\" src=\"https://explaining.ml/images/lemon-logo.png\" />\n\n[![PyPI version](https://badge.fury.io/py/lemon_explainer.svg)](https://badge.fury.io/py/lemon_explainer)\n\n**LEMON** is a technique to explain why predictions of machine learning models are made. It does so by providing feature contribution: a score for each feature that indicates how much it contributed to the final prediction. More precisely, it shows the sensitivity of the feature: a small change in an important feature's value results in a relatively large change in prediction. It is similar to the popular [LIME](https://github.com/marcotcr/lime) explanation technique, but is more faithful to the reference model, especially for larger datasets. \n\n[Website \u2197](https://explaining.ml/lemon)\n[Academic paper \u2197](https://link.springer.com/chapter/10.1007/978-3-031-30047-9_7)\n\n\n## Installation\n\nTo install use pip:\n\n```\n$ pip install lemon-explainer\n```\n\n## Example\nA minimal working example is shown below:\n\n```python\nimport numpy as np\nimport pandas as pd\nfrom sklearn.datasets import load_iris\nfrom sklearn.ensemble import RandomForestClassifier\nfrom lemon import LemonExplainer\n\n# Load dataset\ndata = load_iris(as_frame=True)\nX = data.data\ny = pd.Series(np.array(data.target_names)[data.target])\n\n# Train complex model\nclf = RandomForestClassifier()\nclf.fit(X, y)\n\n# Explain instance\nexplainer = LemonExplainer(X, radius_max=0.5)\ninstance = X.iloc[-1, :]\nexplanation = explainer.explain_instance(instance, clf.predict_proba)[0]\nexplanation.show_in_notebook()\n```\n\n## Development\n\nFor a development installation (requires npm or yarn),\n\n```\n$ git clone https://github.com/iamDecode/lemon.git\n$ cd lemon\n```\n\nYou may want to (create and) activate a virtual environment:\n\n```\n$ python3 -m venv venv\n$ source venv/bin/activate\n```\n\nInstall requirements:\n\n```\n$ pip install -r requirements.txt\n```\n\nAnd run the tests with:\n\n```\n$ pytest .\n```\n\n## Approximate distance kernel LIME\n\nIf you prefer to use a Gaussian distance kernel as used in LIME, we can approximate this behavior with:\n\n```python\nfrom lemon import LemonExplainer, gaussian_kernel\nfrom scipy.special import gammainccinv\n\nDIMENSIONS = X.shape[1]\nKERNEL_SIZE = np.sqrt(DIMENSIONS) * .75  # kernel size as used in LIME\n\n# Obtain a distance kernel very close to LIME's gaussian kernel, see the paper for details.\np = 0.999\nradius = KERNEL_SIZE * np.sqrt(2 * gammainccinv(DIMENSIONS / 2, (1 - p)))\nkernel = lambda x: gaussian_kernel(x, KERNEL_SIZE)\n\nexplainer = LemonExplainer(X, distance_kernel=kernel, radius_max=radius)\n```\n\nThis behavior is as close as possible to LIME, but still yields more faithful explanations due to LEMON's improved sampling technique. Read the paper for more details about this approach.\n\n## Citation\n\nIf you want to refer to our explanation technique, please cite our paper using the following BibTeX entry:\n\n```bibtex\n@inproceedings{collaris2023lemon,\n  title={{LEMON}: Alternative Sampling for More Faithful Explanation Through Local Surrogate Models},\n  author={Collaris, Dennis and Gajane, Pratik and Jorritsma, Joost and van Wijk, Jarke J and Pechenizkiy, Mykola},\n  booktitle={Advances in Intelligent Data Analysis XXI: 21st International Symposium on Intelligent Data Analysis (IDA 2023)},\n  pages={77--90},\n  year={2023},\n  organization={Springer}\n}\n```\n\n## License\n\nThis project is licensed under the BSD 2-Clause License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "lemon-explainer package updated for research usages.",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50c10d056e2e1bb60877543073d0604928950fde9cd61bb84a3098323de1b093",
                "md5": "4d80cd29b8409975f0563de41bcb76f8",
                "sha256": "602698ec5bbd0627bc28c380f4f9908fd6f1c0fde565f744c63637ef3f517e5d"
            },
            "downloads": -1,
            "filename": "lemon_explainer_research_use-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4d80cd29b8409975f0563de41bcb76f8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12188,
            "upload_time": "2024-06-15T08:14:35",
            "upload_time_iso_8601": "2024-06-15T08:14:35.638046Z",
            "url": "https://files.pythonhosted.org/packages/50/c1/0d056e2e1bb60877543073d0604928950fde9cd61bb84a3098323de1b093/lemon_explainer_research_use-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9db839f447590728ab86656d494639dbab4b172e681d5c7b16197dc09206f6a8",
                "md5": "70d78bfb2282b5b6188094422073b2bb",
                "sha256": "886f3907700b679a19df04f1432c48dbc119282eceabb15f25e786733087c1d6"
            },
            "downloads": -1,
            "filename": "lemon-explainer-research-use-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "70d78bfb2282b5b6188094422073b2bb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10584,
            "upload_time": "2024-06-15T08:14:37",
            "upload_time_iso_8601": "2024-06-15T08:14:37.802079Z",
            "url": "https://files.pythonhosted.org/packages/9d/b8/39f447590728ab86656d494639dbab4b172e681d5c7b16197dc09206f6a8/lemon-explainer-research-use-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-15 08:14:37",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "lemon-explainer-research-use"
}
        
Elapsed time: 0.21628s