PDP plotting error

Hello, I’ve been getting an error message I can’t figure out when trying to plot PDP’s from a XGBoost model that I’ve fit. Here’s the code snipped that is throwing the error:

Smooth_PDP = final_model %>%
partial(pred.var = “Nitrogen”, train=as.matrix(dataset[,-1])) %>%
autoplot(smooth = TRUE, ylab = expression(f(Nitrogen))) +
theme_light() +
ggtitle(“Nitrogen PDP”)

The error is:
*Error in if (object$params$objective %in% c(“reg:linear”, “reg:logistic”, : *

  • argument is of length zero*

At one point I made a code change and the error changed to something about “partial plots can only be made for classification and regression models.” I updated all the packages being used, so I hope that’s not an issue. I never specified the objective function in the params of the original fitting of “final_model” , but the default is “reg:squarederror”, which is what I want (this is a regression model), so why is it asking again? I have tried explicitly re-stating the params just above the PDP code, and also adding the params into the function call to partial, but that didn’t seem to help either.

Thanks for any advice!

Hey Mike,

I’ve had the same issue recently. The default objective used to be called “reg:linear”, which has since been deprecated for “reg:squarederror”. If you try duplicating your model and change to objective = "reg:linear" it should give you the same model fit, and a warning that its replaced with reg:squarederror. pdp plots should work with this class.

Most likely the pdp package hasn’t been updated to account for this change of objective default :frowning: