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

Partial dependence plot appears in the opposite way #108

Open
mcchiu opened this issue Apr 27, 2020 · 5 comments
Open

Partial dependence plot appears in the opposite way #108

mcchiu opened this issue Apr 27, 2020 · 5 comments

Comments

@mcchiu
Copy link

mcchiu commented Apr 27, 2020

I build the xgboost model.
The partial dependence plot (red line) appears in the opposite way.
Could you please help out?

set.seed(1278)
xgb_f <- xgboost(data = data, 
                 label = type, 
                 eta = 0.1,
                 max_depth = 15, 
                 nround = 35, 
                 subsample = 0.5,
                 colsample_bytree = 0.5,
                 objective = "reg:squarederror",
                 nthread = 4,
                 verbose = FALSE
)
 xgb_f %>%
    partial(pred.var = "airTEMP", grid.resolution = 100, 
            train = data, ice = TRUE, type = "regression") %>%
    autoplot(rug = TRUE, train = data, alpha = .1, center = TRUE)

image

@bgreenwell
Copy link
Owner

@mcchiu do you have the code to reproduce data and type?

@mcchiu
Copy link
Author

mcchiu commented Apr 28, 2020

@bgreenwell
Here is the code to reproduce data and type.

dataAll <- read.csv("rawdatasub1.csv")
type <- data.matrix(dataAll$aquarticflux)
data <- data.matrix(dataAll[,! names(dataAll) %in% "aquarticflux"])

@bgreenwell
Copy link
Owner

bgreenwell commented Apr 28, 2020

Thanks @mcchiu, I'll take a look. For now, plotPartial(airTEMP, alpha = 0.1, center = TRUE) (which uses lattice) seems to work fine.

@bgreenwell
Copy link
Owner

Still not sure what the exact issue is, but here's a quick fix if you still want to use ggplot2

d <- pdp:::center_ice_curves.ice(airTEMP)  # center manually
ggplot(d, aes(airTEMP, yhat, group = yhat.id)) +
  geom_line(alpha = 0.1) +
  geom_line(data = pdp:::average_ice_curves.ice(d), color = "red",
            aes(airTEMP, yhat), inherit.aes = FALSE)

@mcchiu
Copy link
Author

mcchiu commented Apr 28, 2020

@bgreenwell Thanks for the help. Either works. I look forward to your new release.

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