【发布时间】:2017-03-14 01:26:23
【问题描述】:
我正在尝试使用插入符号库调整 xgboost 的超参数以解决分类问题,由于我的数据集中有很多因素并且 xgboost 喜欢将数据作为数字,我使用特征哈希创建了一个虚拟行,但是当我得到运行 caret train ,我得到一个错误
#Using Feature hashing to convert all the factor variables to dummies
objTrain_hashed = hashed.model.matrix(~., data=train1[,-27], hash.size=2^15, transpose=FALSE)
#created a dense matrix which is normally accepted by xgboost method in R
#Hoping I could pass it caret as well
dmodel <- xgb.DMatrix(objTrain_hashed[, ], label = train1$Walc)
xgb_grid_1 = expand.grid(
nrounds = 500,
max_depth = c(5, 10, 15),
eta = c(0.01, 0.001, 0.0001),
gamma = c(1, 2, 3),
colsample_bytree = c(0.4, 0.7, 1.0),
min_child_weight = c(0.5, 1, 1.5)
)
xgb_trcontrol_1 = trainControl(
method = "cv",
number = 3,
verboseIter = TRUE,
returnData = FALSE,
returnResamp = "all", # save losses across all models
classProbs = TRUE, # set to TRUE for AUC to be computed
summaryFunction = twoClassSummary,
allowParallel = TRUE
)
xgb_train1 <- train(Walc ~.,dmodel,method = 'xgbTree',trControl = xgb_trcontrol_1,
metric = 'accuracy',tunegrid = xgb_grid_1)
我收到以下错误
Error in as.data.frame.default(data) :
cannot coerce class ""xgb.DMatrix"" to a data.frame
有什么建议,我该如何继续?
【问题讨论】: