I want to train a xgboost model,but when I create data partition, it has wrong:
library(data.table)
library(caret)
library(xgboost)
digit <- fread("train.csv",header=T)
index <- createDataPartition(digit$label,0.75,list=F)
Error in matrix(unlist(out), ncol = times) : data is too long
I use another method to create data partition, but here is another problem:
dim(digit)
[1] 42000 785
n <- 42000*0.7
index <- sample(1:42000,n)
train <- digit[index]
test <- digit[-index]
xgmat <- xgb.DMatrix(train[,-1],label=train[,1])
Error in xgb.DMatrix(train[, -1], label = train[, 1]) : xgb.DMatrix: does not support to construct from list In addition: Warning message: In if (class(data) == "dgCMatrix") { : the condition has length > 1 and only the first element will be used
OK, I first transform the data.frame to matrix:
train <- as.matrix(train)
xgmat <- xgb.DMatrix(train[,-1],label=train[,1])
Error in xgb.DMatrix(train[, -1], label = train[, 1]) : REAL() can only be applied to a 'numeric', not a 'integer'
What is wrong on earth? Can anyone help me?