Giter Club home page Giter Club logo

Comments (3)

soundgarden134 avatar soundgarden134 commented on June 2, 2024 4

Hello, and sorry for the late response. I think I didn't explain properly what the problem was. What I want to do basically is to update the plot ShapSummaryComponent with a callback in my custom tab. Whenever I select an area in the preds_map, a new explainer should be created with the filtered data within the map, changing the calculated shap values of the features. WIth this new explainer, I would like to update the ShapSummaryComponent in order to provide insights about particular areas and which features had the biggest impact in these specific areas. Is this possible? Thanks in advance.

UPDATE: I managed to do it. What I did was basically use a callback in my map that recalculates the shap values for the selected area, re calculates the explainer and sets the new explainer for the shap summary component and updates a hidden "P" html element once its finished its calculations.
Then I added in the update_shap_summary_graph another input with this element that I named "shap-hidden-trigger" and every time this element changes, the callback is called again with the new explainer.

shap_components.py

        @app.callback(
            [
                Output("shap-summary-graph-" + self.name, "figure"),
                Output("shap-summary-index-col-" + self.name, "style"),
            ],
            [
                Input("shap-summary-type-" + self.name, "value"),
                Input("shap-summary-depth-" + self.name, "value"),
                Input("shap-summary-index-" + self.name, "value"),
                Input("pos-label-" + self.name, "value"),
                Input("shap-hidden-trigger", "children"),
            ],
        )
        def update_shap_summary_graph(summary_type, depth, index, pos_label, hidden_trigger):
         #rest of the code

my_custom_layout.py

  @app.callback(
            Output('shap-hidden-trigger', 'children'),
            Input('update-shap-button', 'n_clicks'),
            State('preds-map', 'selectedData'),
            prevent_initial_call=True,
        )
        def update_shap_summary(change_settings, selectedData):
             #some processing of the data that I skipped

                shap_explainer = shap.Explainer(predictor)
                shap_values = shap_explainer.shap_values(
                    new_X, 
                    check_additivity=False, 
                    approximate=False
                )
                base_values = shap_explainer.expected_value
                new_explainer = ClassifierExplainer(model=predictor, X=new_X, n_jobs=-1, index_name="Block ID", 
                                                    precision="float32", target="DEPVAR")
                new_explainer.set_shap_values(base_values, shap_values)
                self.shap_summary.explainer = new_explainer
                return "Turing" #just updating to whatever since its hidden

Thanks!

from explainerdashboard.

datatalking avatar datatalking commented on June 2, 2024

Please show a screenshot or copy of the error you get, once we can see what your output is I could pair program with you to see if I can help.

from explainerdashboard.

oegedijk avatar oegedijk commented on June 2, 2024

It looks like you are reinstantiating all the sub components every time there is an update? I don't think that will work. All the components have to be there at the start of the dash app, and then the callbacks update the properties of the components, so the self.update_components() line is probably that breaks things. So get rid of that. The shap values have already been pre-calculated in the explainer that gets passed to the component, so you never reinstantiate the explainer and then recalculate.

So the callback should probably target Output('preds_map', 'figure') instead and then you simply generate the right plot for a subsample.

from explainerdashboard.

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.