Giter VIP home page Giter VIP logo

Comments (8)

connortann avatar connortann commented on May 27, 2024 1

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.

chriscave avatar chriscave commented on May 27, 2024 1

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.

connortann avatar connortann commented on May 27, 2024 1

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.

richarddli avatar richarddli commented on May 27, 2024

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.

sroener avatar sroener commented on May 27, 2024

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.

connortann avatar connortann commented on May 27, 2024

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.

sroener avatar sroener commented on May 27, 2024

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.

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.

connortann avatar connortann commented on May 27, 2024

Sure, we're always happy to have new contributors!

from shap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.