0

I am trying to train any of the penalised models like lasso, but I'm constantly getting this error." Warning: Setting row names on a tibble is deprecated.Warning: model fit failed for Fold01.Rep1: alpha=0.10, lambda=0.04654 Error in (function (x, y, family = c("gaussian", "binomial", "poisson", : "

Here is my code:

new_df$bcpm07c <- as.factor(new_df$bcpm07c )

outcomeName <- "bcpm07c"

predictorsNames <- names(new_df)[names(new_df)!= outcomeName]

ctrl <- trainControl(method="repeatedcv",number = 10,repeats =3 )

fit.lass <- train(Train[,predictorsNames], Train$bcpm07c, family= "binomial", alpha = 1, method='glmnet', trControl=ctrl)

I have tried using changing different ways of splitting the data into x and y but none of them has helped. Checked online but the code seems correct. I checked the dim and it 6048,148 for x_train and (6048,1) for y_train. I don't know where the error is coming from.

UseR10085
  • 7,120
  • 3
  • 24
  • 54
NFB
  • 1
  • You aren't showing us the error, just the warnings that preceded it. You can probably avoid the warning about row names by using a dataframe instead, but without something reproducible, I can't tell whether that really matters. – user2554330 May 10 '23 at 08:55
  • fit.lass <- train(Train[,predictorsNames], Train[outcomeName],family= "binomial", alpha = 1, method='glmnet', trControl=ctrl) Error: Please make sure that the outcome column is a factor or numeric. The class(es) of the column: 'tbl_df', 'tbl', 'data.frame' – NFB May 10 '23 at 09:44
  • Both x and y inputs are data frames so I don't know what's happening and this my first time training in R. – NFB May 10 '23 at 09:46
  • The outcome("bcpm07c") is binary and is factor but when I use Train["bcpm07c"], I get error the above error and when I try as.factor(Train["bcpm07c"]) I get this error,"Error in if (xi > xj) 1L else -1L : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In xtfrm.data.frame(x) : cannot xtfrm data frames 2: In Ops.factor(xi, xj) : ‘>’ not meaningful for factors" – NFB May 10 '23 at 10:00
  • 1
    Please read and follow these suggestions: https://stackoverflow.com/q/5963269/2554330 – user2554330 May 10 '23 at 10:04
  • Please provide enough code so others can better understand or reproduce the problem. – Community May 10 '23 at 14:54

0 Answers0