Comments (8)
From the prototype implementation of this new approach on #3523, I noticed a possible pitfall to avoid. Often the plotting functions are called like this:
def foo():
f = plt.figure()
shap.plots.bar(..., show=False)
return f
To avoid breaking this pattern, we should avoid calling plt.figure()
during the plotting functions, even if ax=None
. Instead, we should continue using plt.gcf()
, which will effectively be the same as plt.figure()
if no current figure exists. This will keep the new code consistent with the library's previous behaviour.
from shap.
Hi, I'm new to contributing and I would love to help out with a few of these. I'm happy to pick up the beeswarm plot.
from shap.
Hi, I'm new to contributing and I would love to help out with a few of these. I'm happy to pick up the beeswarm plot.
@chriscave fantastic, great you to have you as a contributor. Give us a shout if you'd like any pointers - for example, feel free to tag me in a draft PR.
from shap.
For Jupyter notebooks, this approach works great! I'm using SHAP in a web application. Here's some sample code I wrote:
feature_importance = np.mean(np.abs(shap_values.values), axis=0)
feature_names = shap_values.feature_names
feature_names, feature_importance = zip(*sorted(zip(feature_names, feature_importance), key=lambda x: x[1], reverse=True))
I then pass this information into my display layer to render as a real-time HTML chart (in my case, chart.js). Has there been any consideration of an approach where:
- Some of the logic (e.g., feature importance) is refactored into
Explanation
objects (or maybe somewhere else; I'm not that familiar with the code) - Making the various plot functions just do display instead of some of the analysis computation?
This would make it much easier for applications that embed SHAP, and also simplify the logic in the plot functions. But maybe I'm missing something. Happy to chat live if it would be helpful, and also willing to help contribute in this area.
from shap.
Hi, I have a question regarding more complex plots like the heatmap. I looked at the code and it felt like a lot of hacky things are going on to fit the heatmap, the horizontal barplot, the f(x) line plot and the colorbar into one "Axes".
What is the opinion on treating the heatmap as a figure level plot with axes for the sub-elements? The improved API style could be provided by giving the option to pass a figure object, and by adding explicit labels to the axes, it could be easier to modify downstream.
from shap.
What is the opinion on treating the heatmap as a figure level plot with axes for the sub-elements? The improved API style could be provided by giving the option to pass a figure object, and by adding explicit labels to the axes, it could be easier to modify downstream.
The current approach has the advantage that all plots are axes-level plots, so they can have a consistent API. I would prefer to keep the API consistent and keep the visual appearance of the plots the same whilst we modify them. However, I'd be open to that change in future if it makes the implementation significantly clearer.
It would be unusual to accept a fig
as an input argument, as defining which plots should go on which inner axes may become rather complex. It is probably simpler to start by accepting the ax
directly.
from shap.
The current approach has the advantage that all plots are axes-level plots, so they can have a consistent API. I would prefer to keep the API consistent and keep the visual appearance of the plots the same whilst we modify them. However, I'd be open to that change in future if it makes the implementation significantly clearer.
It would be unusual to accept a
fig
as an input argument, as defining which plots should go on which inner axes may become rather complex. It is probably simpler to start by accepting theax
directly.
Thank you for the reply and input. I can see the value of having a consistent API.
I am working on a multi heatmap plot for a multiclass classification problem and would like to try a few things, making it possible to modify the plot a bit (e.g. removing the colorbar, adding a sample annotation) and I'm not entirely sure if that works with the ax level API. @connortann Do you mind, if I tag you in a future PR?
from shap.
Sure, we're always happy to have new contributors!
from shap.
Related Issues (20)
- BUG: Workflow failure on macOS when building 'lightgbm'
- ENH: expose raw feature categories in shap.plots.bar HOT 1
- ENH: Winter Values HOT 4
- [Meta-issue] Release 0.45.1 HOT 5
- BUG: [in version 0.44.0 and 0.45.0] UserWarning: unrecognized nn.Module: Flatten HOT 1
- BUG: 'tuple' object has no attribute 'as_list' HOT 4
- BUG: unable to use SHAP with CUDA support on Windows10/11 machine for calculating Shapley values HOT 1
- Support for KerasClassifier HOT 1
- BUG: Failed in nopython mode pipeline (step: native lowering) float16 HOT 4
- Questions: question about SamplingExplainer HOT 1
- BUG: SHAP values calculated using CPU differ from SHAP values calculated using GPU HOT 5
- BUG: TypeError: ufunc 'isfinite' not supported for the input types HOT 4
- BUG: Additivity check failed HOT 1
- When plotting the shap text it is showing an extra letter(Ġ) before every word. HOT 1
- Demangle pytorch and tensorflow dependencies
- ENH: Python 3.13 Support
- TypeError: In v0.20, force plot now requires the base value as the first parameter! Try shap.plots.force(explainer.expected_value, shap_values) or for multi-output models try shap.plots.force(explainer.expected_value[0], shap_values[0]). HOT 1
- Key not found with shap.TreeExplainer and XGBRegressor HOT 1
- BUG: Unable to Generate SHAP values for a dataframe containing text data trained on lstm model HOT 2
- BUG: Error with SHAP Partial Dependence Plot: ValueError: DataFrame.dtypes for data must be int, float, bool or category
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shap.