【发布时间】:2018-02-15 11:19:16
【问题描述】:
据我所知,XGB 应该有处理丢失数据的好处,但是,每当我测试添加了一些 NA 的波士顿住房集时,我都会收到错误:
The length of labels must equal to the number of rows in the input data
我运行的代码是
trainm <- sparse.model.matrix(class ~ ., data = train)
train_label <- train[,"class"]
train_matrix <- xgb.DMatrix(data = as.matrix(trainm) label=train_label)
当我不添加 NA 时,一切运行正常。我很确定问题是从稀疏矩阵中删除了 NA,这会导致混淆,但我不知道如何解决。
我的代码是here。
我们将非常感谢任何可以帮助我的反馈。
【问题讨论】:
-
问题不在于
NA。train_label中的观察数与trainm中的观察数不同。如果您执行dim(trainm),您将获得369 x 15,而length(train_label)将返回您403。 -
感谢您的评论。如果我注释掉“### Add a few NAs”部分(第 29-33 行),那么一切正常,所以除非我误解了某些内容,否则错误是由于缺少某些数据引起的?
-
是的,如果您注释这些代码行,您将能够运行
xgb.DMatrix。
标签: r sparse-matrix xgboost