使用pdp包进行分类xgboost的部分依赖关系图

时间:2018-01-15 06:49:43

标签: r

我使用pdp包来运行部分依赖性线性回归使用xgboost包是完美的,没有任何警告。但是当我改为xgboost的分类(logistic)标签时。我得到了部分依赖的警告消息,说部分依赖是基于线性的,如下所示。请问是否必须以某种方式修改代码以使用xgboost包精确地提供分类对象,以便部分依赖性是正确的。或者我可以忽略警告信息,它已经是正确的。我知道randomforest很直接,没有任何警告信息

# Load required packages
library(pdp)
library(xgboost)

# Simulate training data with ten million records
set.seed(101)
trn <- as.data.frame(mlbench::mlbench.friedman1(n = 1e+07, sd = 1))
trn=trn[sample(nrow(trn), 500), ]
trn$y=ifelse(trn$y>16,1,0)

# Fit an XGBoost classification(logistic) model
set.seed(102)
bst <- xgboost(data = data.matrix(subset(trn, select = -y)),
           label = trn$y,
           objective = "reg:logistic",
           nrounds = 100,
           max_depth = 2,
           eta = 0.1)
 #partial dependency plot

  pd <- partial(bst$handle,
            pred.var = c("x.1"), 
            grid.resolution = 10, 
            train = data.matrix(subset(trn, select = -y)),
            prob=TRUE,
            plot = FALSE,
            .progress = "text")

 Warning message:
 In superType.default(object) :
 `type` could not be determined; assuming `type = "regression"`

1 个答案:

答案 0 :(得分:0)

在这种情况下,您可以放心地忽略警告;然而,它确实导致了pdp包中的一个小错误,我将很快推出修复程序。谢谢你的举报!