monte-flora / py-mint

Python scripts for machine learning interpretability methods
MIT License
12 stars 2 forks source link

Crash in tutorial notebook `feature_contributions.ipynb` #85

Open jvpeetz opened 2 years ago

jvpeetz commented 2 years ago

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:

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 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.

monte-flora commented 2 years ago

I will note that py-mint has been re-branded as scikit-explain (https://github.com/monte-flora/scikit-explain). New changes to the package will be made there. Several changes have been made to improve the package. If you continue to have this use with scikit-explain, please raise the issue on that github page. If you have any questions, feel free to ask!