xgboost错误:setinfo.xgb.DMatrix(dmat,names(p),p [[1]])错误:标签的长度必须等于输入数据中的行数

问题描述 投票:0回答:1
sparse_matrix <- sparse.model.matrix(state ~ . -Month -LanID, data = smoted_data) smoted_data_mat_label<-as.matrix(as.numeric(smoted_data$state)) smoted_data_mat_label = smoted_data[,"state"] == 1 xgb.fit <- xgboost( data = sparse_matrix, label = smoted_data_mat_label, eta = 1.8, max_depth = 7, min_child_weight = 11, # could be anything all are showing same results nrounds = 9, # could be anything all are showing same results nfold = 10, objective = "binary:logistic", # for regression models verbose = 1, # silent, early_stopping_rounds = 10 # stop if no improvement for 10 consecutive trees ) Error in setinfo.xgb.DMatrix(dmat, names(p), p[[1]]) : The length of labels must equal to the number of rows in the input data length(smoted_data_mat_label) [1] 22721 > length(sparse_matrix) [1] 41739681 dim(smoted_data) [1] 22721 31 length(smoted_data$LanID) [1] 22721
以前的代码运行良好,现在导致下面的错误,不确定为什么?我检查了sparse_matrix的类,它是矩阵,标号也是一个矩阵。
machine-learning xgboost
1个回答
0
投票
之所以发生此问题,是因为在新数据中引入了一些NA。删除了NA,算法运行良好。
© www.soinside.com 2019 - 2024. All rights reserved.