简体   繁体   English

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

[英]partial dependency plot using pdp package for classification xgboost

I use pdp package to run partial dependency for linear regression using xgboost package is perfect without any warning. 我使用pdp包运行部分依赖关系,使用xgboost包进行线性回归是完美的,没有任何警告。 But when I change to classification(logistic) label for xgboost. 但是,当我更改为xgboost的分类(物流)标签时。 I got the warning messages for partial dependency say the partial dependency is based on linear as follows. 我收到了有关部分依赖的警告消息,说部分依赖是基于线性的,如下所示。 May I ask if the code has to be revised in somehow to exactly feed classification object using xgboost package so that the partial dependency is correct. 请问是否必须以某种方式修改代码以使用xgboost软件包准确地提供分类对象,以便部分依赖项是正确的。 Or I can ignore the warning message , it is correct already. 或者我可以忽略警告消息,它已经正确了。 I know randomforest is straight forward without any warning messages 我知道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"`

In this case, you can safely ignore the warning; 在这种情况下,您可以放心地忽略警告。 however, it did lead me to a small bug in the pdp package for which I will push a fix to shortly. 但是,它的确导致我发现了pdp软件包中的一个小错误,我将很快对此进行修复。 Thanks for reporting! 感谢您的举报!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM