这是火车功能xgboost()
的错误吗?火车标签被更新为numeric
,但我仍然看到相同的错误,即日志记录标签必须为[0,1]。
第一种方法。
train.y <- as.factor(train.y)
levels(train.y)[levels(train.y) =='klar'] <- 0
levels(train.y)[levels(train.y) =='trüb'] <- 1
train.y <- as.numeric(train.y)
第二种方法。
train.y <- as.numeric(as.factor(train.y))
> class(train.y)
[1] "numeric"
# convert dataset into Dmatrix
dtrain <- xgb.DMatrix(data =as.matrix(train.x), label= train.y)
# train model
model.xgb <- xgboost(data = dtrain, # the data
max.depth = 3,
nround = 50, # boosting iterations
objective = "binary:logistic") # the objective function
Error in xgb.iter.update(bst$handle, dtrain, iteration - 1, obj) :
[12:55:32] amalgamation/../src/objective/regression_obj.cc:98: Check failed: Loss::CheckLabel(y) label must be in [0,1] for logistic regression
我该如何解决?
类似的问题报告为here。我已经报告了这个here,但以防万一有人已经解决了这个问题。
这是一个可复制的示例。
train.x <- matrix(rexp(5000), ncol = 10)
train.y <- rep(c('klar', 'trüb'), times=250)
train.y <- as.numeric(as.factor(train.y))
dtrain <- xgb.DMatrix(as.matrix(train.x), label=train.y)