{"id":19562181,"url":"https://github.com/iamdecode/lemon","last_synced_at":"2025-04-27T00:31:31.791Z","repository":{"id":195853238,"uuid":"178884665","full_name":"iamDecode/lemon","owner":"iamDecode","description":"The LEMON machine learning explanation technique 🍋","archived":false,"fork":false,"pushed_at":"2024-04-10T11:45:35.000Z","size":71,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-20T01:10:06.110Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://explaining.ml/lemon","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iamDecode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-04-01T14:47:20.000Z","updated_at":"2023-10-08T13:44:34.000Z","dependencies_parsed_at":"2024-04-10T10:28:20.689Z","dependency_job_id":"5000327a-5fe1-4fd0-992b-8822e05306af","html_url":"https://github.com/iamDecode/lemon","commit_stats":null,"previous_names":["iamdecode/lemon"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamDecode%2Flemon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamDecode%2Flemon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamDecode%2Flemon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamDecode%2Flemon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamDecode","download_url":"https://codeload.github.com/iamDecode/lemon/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251072279,"owners_count":21532004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T05:13:54.693Z","updated_at":"2025-04-27T00:31:31.511Z","avatar_url":"https://github.com/iamDecode.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg width=\"250\" src=\"https://explaining.ml/images/lemon-logo.png\" /\u003e\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 ↗](https://explaining.ml/lemon)\n[Academic paper ↗](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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamdecode%2Flemon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamdecode%2Flemon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamdecode%2Flemon/lists"}