Error Message "x should be a matrix with 2 or more columns" Lasso Regression with caret package

Hi all! I have been playing around with the caret package and tried a LASSO regression model on the R dataset Lake Huron. However, when I run my model, I get the error message "model fit failed for Fold1: x should be a matrix with 2 or more columns". Could anyone elaborate on what I'm doing wrong? I will post my code below. Thanks already for the help in advance!




index <- createDataPartition(df$x, p=.8, list=FALSE, times=1) 

train_df <- df[index,] 
test_df <- df[-index,] 

ctrlspecs <- trainControl(method="cv", number=2, 

lambda_vector <- 10^seq(5, -5, length=500)

model1 <- train( x ~ Time, 
                 data = train_df,
                 preProcess = c("center", "scale"),
                 method = "glmnet",
                 tuneGrid = expand.grid(alpha=1, lambda=lambda_vector),
                 trControl = ctrlspecs, 
                 na.action = na.omit)

The glmnet maintainers put in the constraint that you need to have 2+ predictors. It looks like you have one called Time.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.