gpt4 book ai didi

R-XGBoost : Error building DMatrix

转载 作者:行者123 更新时间:2023-11-30 08:22:36 24 4
gpt4 key购买 nike

我在 R 中使用 XGBoost 时遇到问题。我正在读取包含我的数据的 CSV 文件:

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))
}

这个函数被称为我的main.R

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

问题出在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)
}

这是错误:

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$

如您所见,它们都是 DataFrame。

我不知道我做错了什么,请帮忙!

最佳答案

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

关于R-XGBoost : Error building DMatrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42743460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com