Reputation: 169
Getting the error Error: nrow(x) == n is not TRUE
when I am using Caret, can anyone help. See example below
Get Wisconsin Breast Cancer dataset and load required libraries
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)
Also apply median imputation to model for missing data
model <- train(
x = breast_cancer_x,
y = breast_cancer_y,
method = "glmnet",
trControl = myControl,
preProcess = "medianImpute"
)
Getting this error -
Error: nrow(x) == n is not TRUE
Upvotes: 1
Views: 1850
Reputation: 6222
Here, breast_cancer_y
is a data.frame. Consider using y = breast_cancer_y$Class
in the train
function.
You also have a character column in breast_cancer_x
; the Id
columns.
I am still getting some other error messages after fixing these. These appear related to pre-processing and control.
Upvotes: 0