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

regression stats to shap.plot.dependence? #7

Closed
arupakaa opened this issue Apr 27, 2020 · 3 comments
Closed

regression stats to shap.plot.dependence? #7

arupakaa opened this issue Apr 27, 2020 · 3 comments

Comments

@arupakaa
Copy link

arupakaa commented Apr 27, 2020

Dear Colleague,

You hard work is very much appreciated, as is your kind attention.

shap.plot.dependence is important validating the output of the SHAP model.
The histogram option is very useful for this, as is the smooth option.
However, the latter almost demands that the linear equation and R-squared be shown.

Would it be possible to implement as an option in shap.plot.dependence?

There is some easy code that enables this, found here:
https://gist.github.com/kdauria/524eade46135f6348140

And here is an example of it being used in practice, with output below:
library(devtools) source_gist("524eade46135f6348140") df = data.frame(x = c(1:100)) df$y = 2 + 5 * df$x + rnorm(100, sd = 40) df$class = rep(1:2,50) ggplot(data = df, aes(x = x, y = y, label=y)) + stat_smooth_func(geom="text",method="lm",hjust=0,parse=TRUE) + geom_smooth(method="lm",se=FALSE) + geom_point() + facet_wrap(~class)

image

Thanks in advance!

@liuyanguu
Copy link
Owner

Very cool. I will take a look! Many thanks

@liuyanguu
Copy link
Owner

Now in the latest version (0.0.4) there is an option to show Pearson correlation which is basically

plot1 <- plot1 + ggpubr::stat_cor(method = "pearson")

The default smooth line uses loess since most relationships are not linear. But you can make it linear by adding the geom_smooth yourself since the output is ggplot2 object (please turn add_hist off otherwise it is no longer ggplot2 object)

shap.plot.dependence(data_long = shap_long_iris, x="Petal.Length",
                     add_hist = FALSE, smooth = FALSE, add_stat_cor = TRUE) + 
  ggplot2::geom_smooth(method = 'lm', color = 'red', size = 0.4, se = F)

sample2

the default:

shap.plot.dependence(data_long = shap_long_iris, x="Petal.Length",
                     add_hist = TRUE, add_stat_cor = TRUE)

sample1

@arupakaa
Copy link
Author

arupakaa commented Jun 5, 2020

This is amazing. Thank you once again for the quick and responsive turn-around. Excellent progress being made all about. Cheers!

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

No branches or pull requests

2 participants