The code proposed to reproduce Figure 5.7 (pag.118) does not seem to work correctly.
pred.fun <- function(object, newdata) {
Yes <- mean(predict(object, newdata, type = "prob")$Yes)
as.data.frame(Yes)}
p1 <- pdp::partial(cv_model3, pred.var = "OverTime", pred.fun=pred.fun) %>%
autoplot(rug = TRUE) + ylim(c(0, 1))
Error in ggplot_two_predictor_pdp(object = object, rug = rug, smooth = smooth, :
The training data must be supplied for rug display.
It is possible that the proposed prediction function does not generate an acceptable data frame for the "partial" function, since when executing:
pdp::partial(cv_model3, pred.var = "OverTime", pred.fun=pred.fun)
you get the following:
OverTime yhat.Yes yhat.Yes
1 No 0.1044187 0.31364
2 Yes 0.1044187 0.31364
What can I be doing wrong or what should be corrected in the code?
Thank you
The code proposed to reproduce Figure 5.7 (pag.118) does not seem to work correctly.
pred.fun <- function(object, newdata) { Yes <- mean(predict(object, newdata, type = "prob")$Yes) as.data.frame(Yes)} p1 <- pdp::partial(cv_model3, pred.var = "OverTime", pred.fun=pred.fun) %>% autoplot(rug = TRUE) + ylim(c(0, 1)) Error in ggplot_two_predictor_pdp(object = object, rug = rug, smooth = smooth, : The training data must be supplied for rug display.
It is possible that the proposed prediction function does not generate an acceptable data frame for the "partial" function, since when executing:
What can I be doing wrong or what should be corrected in the code? Thank you