Skip to content

Crash in tutorial notebook feature_contributions.ipynb #85

Description

@jvpeetz

Thank you very much for developing this project further.
Recently, I took another look at your tutorial notebooks. In this and a second issue I'd like to discuss some suggestions.
I used the following versions for the underlying Python modules:

  • pandas: 1.1.5
  • scikit-learn: 1.0.2
  • shap: 0.40.0
  • py-mint: 0.2.6

In order to use the current scikit-learn version 1.1 further adaptions would be necessary. To keep up with the version changes of the underlying Python modules can be a hard job, as far as I know. Maybe, it's a good idea to print out the version numbers of the underlying Python modules in the notebooks?
This issue is about your notebook feature_contributions.ipynb which crashes in the local_contributions() function with the parameter method='shap'. I made it working again with two modifications in main/local_interpret.py:

  • the call of self._get_feature_contributions() in line 172 needs the additional argument shap_kwargs=shap_kwargs
  • the output of shap seems to have changed; in line 235 I tried to fix it by setting bias = shap_results.base_values[0]

The patch file looks like this:

--- local_interpret.py.orig	2022-07-12 21:21:48.300547909 +0200
+++ local_interpret.py	2022-07-20 21:39:22.572689921 +0200
@@ -172,6 +172,7 @@
                     cont_dict = self._get_feature_contributions(
                         estimator=estimator,
                         X=self.X.iloc[indices, :],
+                        shap_kwargs=shap_kwargs,
                     )
 
                     contributions_dict[estimator_name][key] = cont_dict
@@ -232,7 +233,7 @@
             shap_results = shap_results[...,1]
         
         contributions = shap_results.values
-        bias = shap_results.base_values
+        bias = shap_results.base_values[0]
 
         return contributions, bias

I didn't dig deep into the Shap package. So maybe, the right correction looks different?
Best regards,
Jörg.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions