NorskRegnesentral / shapr

Explaining the output of machine learning models with more accurately estimated Shapley values
https://norskregnesentral.github.io/shapr/
Other
138 stars 32 forks source link

Added keras support #345

Closed rawanmahdi closed 11 months ago

rawanmahdi commented 1 year ago

Implemented keras predict function. I also added an example using the shapr iris dataset on a sequential keras model and running explain(). I have not yet figured out how to implement the get_model_specs function for keras, as I am not sure if there is a way to access feature names through the model alone. This is my first PR so apologies in advance for any issues, and please let me know if theres anything to add/fix! Thanks :)

martinju commented 1 year ago

Thanks, will look at this next week. Please try to see if it is possible to define a get_model_specs function, with at least the feature names. This would make it much more secure to use in practice.

rawanmahdi commented 1 year ago

I looked into implementing the get_model_specs function some more, and I asked on stack overflow if there was a way of obtaining feature names. The answer I got:

"No, unlike sklearn there isn't a Keras/Tensorflow equivalent for obtaining feature names. This is because tensorflow-keras models focus more on the shape and dimensions of the input tensors rather than the individual features. The model utilizes the input features as tensors, regardless of name."

I think the only work around for validating between the dataset and the model would be to check feature_size or feature_type, however from what I can see that would require updating R internals as well. I'm not too familiar with R, however I'll look into it for a seperate PR.