【问题标题】:Caret Getting Error: nrow(x) == n is not TRUE插入符号出现错误:nrow(x) == n 不是 TRUE
【发布时间】:2018-05-26 19:25:26
【问题描述】:

当我使用 Caret 时收到错误 Error: nrow(x) == n is not TRUE,任何人都可以帮忙。请参阅下面的示例

获取 Wisconsin Breast Cancer 数据集并加载所需的库

library(dplyr)
library(caret)
library(mlbench)
data(BreastCancer)

myControl = trainControl(
method = "cv", number = 5,
repeats = 5, verboseIter = TRUE
)

breast_cancer_y <- BreastCancer %>%
  dplyr::select(Class)

breast_cancer_x <- BreastCancer %>%
  dplyr::select(-Class)

还对缺失数据的模型应用中值插补

model <- train(
  x = breast_cancer_x,
  y = breast_cancer_y,
  method = "glmnet",
  trControl = myControl,
  preProcess = "medianImpute"
  )

收到此错误 -

错误:nrow(x) == n 不正确

【问题讨论】:

    标签: r r-caret


    【解决方案1】:

    这里,breast_cancer_y 是一个 data.frame。考虑在train 函数中使用y = breast_cancer_y$Class

    breast_cancer_x 中还有一个字符列; Id 列。

    修复这些问题后,我仍然收到一些其他错误消息。这些似乎与预处理和控制有关。

    【讨论】:

    • 新的错误信息与另一个问题有关。
    • 是不是和包含因子的数据有关?
    • 我觉得你应该看看here
    • 我不知道glmnet,我认为有些列需要是数字的。我想你应该尝试插入一些列数字等。
    猜你喜欢
    • 1970-01-01
    • 2015-01-18
    • 2016-02-15
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    相关资源
    最近更新 更多