【问题标题】:xgboost error : Error in setinfo.xgb.DMatrix(dmat, names(p), p[[1]]) : The length of labels must equal to the number of rows in the input dataxgboost 错误:setinfo.xgb.DMatrix(dmat, names(p), p[[1]]) 中的错误:标签的长度必须等于输入数据中的行数
【发布时间】:2020-04-26 19:08:38
【问题描述】:
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】:

    出现此问题是因为在新数据中引入了一些 NA。删除了 NA,算法运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      相关资源
      最近更新 更多