在尝试将xgboost包中包含的xgb.create.features(model,data,...)函数应用于R并在用户手册中介绍时,我遇到了一个我不明白的异常。这是一个可重复的例子:
ibrary(xgboost)
data(mtcars)
X = as.matrix(mtcars[, -9])
Y = mtcars$am
dtrain = xgb.DMatrix(data = X, label = Y)
model = xgb.train(data = dtrain,
feval = performance_fun_F,
verbose =0, maximize = TRUE,
params = list(objective = "binary:logistic",
eta = 0.1,
max_depth = 6,
subsample = 0.8,
lambda = 0.1 ),
nrounds = 10)
dtrain1 = xgb.create.features(model, dtrain)
Error: not-yet-implemented method for cbind2(<xgb.DMatrix>, <dgCMatrix>).
->> Ask the package authors to implement the missing feature.
Traceback:
1. xgb.create.features(model, dtrain)
2. cBind(data, sparse.model.matrix(~. - 1, cols))
3. base::cbind(..., deparse.level = deparse.level)
4. cbind(deparse.level, ...)
5. cbind2(..1, r)
6. cbind2(..1, r)
7. .bail.out.2(.Generic, class(x), class(y))
8. stop(gettextf("not-yet-implemented method for %s(<%s>, <%s>).\n ->> Ask the package authors to implement the missing feature.",
. fun, cl1[1L], cl2[1L]), call. = FALSE, domain = NA)
您的建议将不胜感激。
答案 0 :(得分:1)
您应该向X
而不是xgb.create.features
提供矩阵dtrain
:
示例:
library(xgboost)
data(mtcars)
X = as.matrix(mtcars[, -9])
dtrain = xgb.DMatrix(data = X, label = Y)
model = xgb.train(data = dtrain,
eval = "auc",
verbose =0, maximize = TRUE,
params = list(objective = "binary:logistic",
eta = 0.1,
max_depth = 6,
subsample = 0.8,
lambda = 0.1 ),
nrounds = 10)
dtrain1 = xgb.create.features(model, X)
dtrain1 = xgb.DMatrix(data = dtrain1, label = Y)
现在:
bst <- xgb.train(data = dtrain1,
eval = "auc",
verbose =0, maximize = TRUE,
params = list(objective = "binary:logistic",
eta = 0.1,
max_depth = 6,
subsample = 0.8,
lambda = 0.1 ),
nrounds = 10)