XGBoost: Error building DMatrix

I am having trouble using the XGBoost in R. I am reading a CSV file with my data:

get_data = function()
{
#Loading Data
path = "dados_eye.csv"
data = read.csv(path)

#Dividing into two groups
train_porcentage = 0.05
train_lines = nrow(data)*train_porcentage
train = data[1:train_lines,]
test = data[train_lines:nrow(data),]
rownames(train) = c(1:nrow(train))
rownames(test) = c(1:nrow(test))

return (list("test" = test, "train" = train))
}

This function is Called my the main.R

lista_dados = get_data()
#machine = train_svm(lista_dados$train)
#machine = train_rf(lista_dados$train)
machine = train_xgt(lista_dados$train)

The problem is here in the train_xgt

train_xgt = function(train_data)
{
data_train = data.frame(train_data[,1:14])
label_train = data.frame(factor(train_data[,15]))

print(is.data.frame(data_train))
print(is.data.frame(label_train))

dtrain = xgb.DMatrix(data_train, label=label_train)
machine = xgboost(dtrain, num_class = 4 ,max.depth = 2, 
    eta = 1, nround = 2,nthread = 2, 
    objective = "binary:logistic")

return (machine)    
}

This is the Error:

becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$ Rscript main.R

[1] TRUE

[1] TRUE

Error in xgb.DMatrix(data_train, label = label_train) :
xgb.DMatrix: does not support to construct from list Calls: train_xgt -> xgb.DMatrix Execution halted becchi@ubuntu:~/Documents/EEG_DATA/Dados_Eye$

As you can see, they are both DataFrames.

I dont know what I am doing wrong, please help!


首先使用as.matrix()将数据帧转换为矩阵,然后传递给xgb.Dmatrix()


Check if all columns have numeric data in them- I think this could be because you have some column that has data stored as factors/ characters which it won't be able to convert to a matrix. if you have factor variables, you can use one-hot encoding to convert them into dummy variables.

链接地址: http://www.djcxy.com/p/95610.html

上一篇: 垂直和水平对齐checkBoxGroupInput

下一篇: XGBoost:构建DMatrix时出错