Partial dependence/ALE/ICE plots XgBoost in r

1k views Asked by At

I am trying to plot pdp, ale and ICE plots for a regression Xgboost model in r built using the Xgboost library. I have tried this using the pdp library:

library(pdp)

    xv <- data.matrix(subset(data, select = -ICP))  # training features
    p1xv <- partial(xgbc, pred.var = "za1", ice = TRUE, center = TRUE, 
    plot = TRUE, rug = TRUE, alpha = 0.1, plot.engine = "ggplot2", train = xv)

I am getting the following error:

Error in partial.default(xgbc, pred.var = "za1", ice = TRUE, center = TRUE, : Partial dependence values are currently only available for classification and regression problems.

Although the model is functional and I managed to plot the breakdown plots using modelstudio. Any ideas on the reason for the error? Is there a parameter in the model that needs to be defined specifically to generate these plots. za1 is a numerical variable.

1

There are 1 answers

0
user3624359 On BEST ANSWER

You need to specify the type. If ICP is continuous, try

p1xv <- partial(xgbc, pred.var = "za1", ice = TRUE, center = TRUE, plot = TRUE, rug = TRUE, alpha = 0.1, plot.engine = "ggplot2", train = xv, type = "regression")