部分 dependence/ALE/ICE 在 r 中绘制 XgBoost

Partial dependence/ALE/ICE plots XgBoost in r

我正在尝试为使用 Xgboost 库构建的 r 回归 Xgboost 模型绘制 pdp、ale 和 ICE 图。 我已经使用 pdp 库尝试过这个:

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)

我收到以下错误:

错误 partial.default(xgbc, pred.var = "za1", ice = TRUE, center = TRUE, : 偏相关值目前仅适用于分类和回归问题。

虽然该模型可以正常运行,但我设法使用 modelstudio 绘制了分解图。 关于错误原因的任何想法?模型中是否有一个参数需要专门定义才能生成这些图。 za1是一个数值变量。

您需要指定类型。如果ICP是连续的,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")