{"id":15288076,"url":"https://github.com/snehankekre/streamlit-shap","last_synced_at":"2025-08-21T04:30:32.952Z","repository":{"id":47700175,"uuid":"454021303","full_name":"snehankekre/streamlit-shap","owner":"snehankekre","description":"streamlit-shap provides a wrapper to display SHAP plots in Streamlit.","archived":false,"fork":false,"pushed_at":"2022-07-21T06:52:56.000Z","size":4739,"stargazers_count":86,"open_issues_count":3,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-16T07:45:16.096Z","etag":null,"topics":["explainability","interpretability","machine-learning","shap","shapley","streamlit","streamlit-component"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/streamlit-shap/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/snehankekre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-31T13:41:19.000Z","updated_at":"2025-04-09T15:23:20.000Z","dependencies_parsed_at":"2022-08-24T21:41:42.109Z","dependency_job_id":null,"html_url":"https://github.com/snehankekre/streamlit-shap","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/snehankekre/streamlit-shap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snehankekre%2Fstreamlit-shap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snehankekre%2Fstreamlit-shap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snehankekre%2Fstreamlit-shap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snehankekre%2Fstreamlit-shap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snehankekre","download_url":"https://codeload.github.com/snehankekre/streamlit-shap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snehankekre%2Fstreamlit-shap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271424921,"owners_count":24757365,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["explainability","interpretability","machine-learning","shap","shapley","streamlit","streamlit-component"],"created_at":"2024-09-30T15:44:03.858Z","updated_at":"2025-08-21T04:30:32.332Z","avatar_url":"https://github.com/snehankekre.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# streamlit-shap\n\nThis component provides a wrapper to display [SHAP](https://github.com/slundberg/shap) plots in [Streamlit](https://streamlit.io/).\n\n### Installation\n\nFirst install Streamlit (of course!) then pip install this library:\n\n```bash\npip install streamlit\npip install streamlit-shap\n```\n\n### Example\n\n```python\nimport streamlit as st\nfrom streamlit_shap import st_shap\nimport shap\n\nfrom sklearn.model_selection import train_test_split\nimport xgboost\n\nimport numpy as np\nimport pandas as pd\n\n\n@st.experimental_memo\ndef load_data():\n    return shap.datasets.adult()\n\n@st.experimental_memo\ndef load_model(X, y):\n    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=7)\n    d_train = xgboost.DMatrix(X_train, label=y_train)\n    d_test = xgboost.DMatrix(X_test, label=y_test)\n    params = {\n        \"eta\": 0.01,\n        \"objective\": \"binary:logistic\",\n        \"subsample\": 0.5,\n        \"base_score\": np.mean(y_train),\n        \"eval_metric\": \"logloss\",\n        \"n_jobs\": -1,\n    }\n    model = xgboost.train(params, d_train, 10, evals = [(d_test, \"test\")], verbose_eval=100, early_stopping_rounds=20)\n    return model\n\nst.title(\"SHAP in Streamlit\")\n\n# train XGBoost model\nX,y = load_data()\nX_display,y_display = shap.datasets.adult(display=True)\n\nmodel = load_model(X, y)\n\n# compute SHAP values\nexplainer = shap.Explainer(model, X)\nshap_values = explainer(X)\n\nst_shap(shap.plots.waterfall(shap_values[0]), height=300)\nst_shap(shap.plots.beeswarm(shap_values), height=300)\n\nexplainer = shap.TreeExplainer(model)\nshap_values = explainer.shap_values(X)\n\nst_shap(shap.force_plot(explainer.expected_value, shap_values[0,:], X_display.iloc[0,:]), height=200, width=1000)\nst_shap(shap.force_plot(explainer.expected_value, shap_values[:1000,:], X_display.iloc[:1000,:]), height=400, width=1000)\n\n```\n\n![st_shap](example.gif)\n\n\n#### Notes\n\nColorbar changes in `matplotlib\u003e3.4.3` introduced bugs ([#22625](https://github.com/matplotlib/matplotlib/issues/22625), [#22087](https://github.com/matplotlib/matplotlib/issues/22087)) that cause the colorbar of certain shap plots (e.g. `beeswarm`) to not display properly. If colorbars are not displayed properly, try downgrading `matplotlib` to `3.4.3`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnehankekre%2Fstreamlit-shap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnehankekre%2Fstreamlit-shap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnehankekre%2Fstreamlit-shap/lists"}