Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explainer api for local classifiers #102

Closed

Conversation

ashishpatel16
Copy link
Collaborator

This PR aims to introduce explainer class which uses shap to compute shapley values for each classifier present at a specific position in the hierarchy.

Copy link

@Paula-Kli Paula-Kli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jannikgro and me had a look into it!
Great work - thanks for sharing! We will now try to use it to gain more insights but here are a few first thoughts from us about it!

for node in self.hierarchical_model.nodes:
model_at_node = self.hierarchical_model.get_model_at_node(node)
# Create a SHAP explainer for each node model
self.explainers[node] = shap.Explainer(model_at_node, background_data[node])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you hard-coded the Explainer class from shap instead of the subclasses that you found out earlier - doesn't that overwrite the choice the user took earlier?

in addition as a user having to sort the data for each node without knowing how you traverse it might it make hard to create the expected dictionary that is reference by background_data[node] don't you think? Would it be possible for you to sort that? (No is a valid answer ;))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed


def _explain_lcppn(self, X):
shap_values_dict = {}
# TODO: Use predictions to restrict traversal to only visited path while computing shap values

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One idea would be to use the predict method of the individual classifiers which points you the way to the next node doesn't it?

shap_values = local_explainer.shap_values(X)
shap_values_dict[parent_node] = shap_values

return shap_values_dict

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool to have as a dictionary but not 100% useful if we do not know which was the predicted and/or the correct path the model has chosen. Would it be possible to return the predicted label and the corresponding shap values?

tests/test_LocalClassifierPerParentNode.py Outdated Show resolved Hide resolved
@Paula-Kli
Copy link

We are not completely sure, because you wanted the explainer to be installable via a pip flag which we might have missed but as we installed it, the Explainer was not immediately available. Instead, you might need to add it to the __init__.py in the hiclass folder - is that possible?

hiclass/Explainer.py Outdated Show resolved Hide resolved
hiclass/Explainer.py Outdated Show resolved Hide resolved
@ashishpatel16 ashishpatel16 changed the title Explainer api Explainer api for local classifier per parent node Jan 12, 2024
@mirand863 mirand863 marked this pull request as draft January 15, 2024 11:14
model.hierarchy_.nodes[node]["classifier"]
for node in model.hierarchy_.nodes
if "classifier" in model.hierarchy_.nodes[node]
def get_predict_proba(self, X):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jannikgro I have updated the function to return a dict, however it currently just returns predict_proba for all nodes in the hierarchy. I'm woking on another version which only gives the dict for only traversed nodes.

@ashishpatel16 ashishpatel16 changed the title Explainer api for local classifier per parent node Explainer api for local classifiers Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants