gpt4 book ai didi

r - xgb.DMatrix 错误 : The length of labels must equal to the number of rows in the input data

转载 作者:行者123 更新时间:2023-12-01 09:52:16 26 4
gpt4 key购买 nike

我在 R 中使用 xgboost。

我使用矩阵作为输入很好地创建了 xgb 矩阵,但是当我减少矩阵数据中的列数时,我收到一个错误。

这有效:

> dim(ctt1)

[1] 6401 5901

> xgbmat1 <- xgb.DMatrix(
Matrix(data.matrix(ctt1)),
label = as.matrix(as.numeric(data$V2)) - 1
)

这不会:
> dim(ctt1[,nr])

[1] 6401 1048

xgbmat1 <- xgb.DMatrix(
Matrix(data.matrix(ctt1[,nr])),
label = as.matrix(as.numeric(data$V2)) - 1)

Error in xgb.setinfo(dmat, names(p), p[[1]]) : The length of labels must equal to the number of rows in the input data

最佳答案

就我而言,我通过更改分配操作来修复此错误:
labels <- df_train$target_feature

关于r - xgb.DMatrix 错误 : The length of labels must equal to the number of rows in the input data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35852923/

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