InaJA
InaJA

Reputation: 21

Error with "select_best" function with tune

I am encountering an error with the select_best() function from the tune package.

lowest_auc <- lasso_res  %>% select_best("roc_auc")

Error in `select_best()`:
! `...` must be empty.
✖ Problematic argument:
• ..1 = "roc_auc"

The error occurred when updating R and packages to:

But runs fine with versions:

Any help is appreciated :)

train <- data.frame(G = c("C", "C", "C", "C", "C", "C", "D", "D", "D", "D"),
                     prot1 = c(1:10),
                     prot2 = c(20:29),
                     prot3 = c(45:54)) 

test <- data.frame(G = c("C", "C", "C", "D", "D", "D"),
                    prot1 = c(1:6),
                    prot2 = c(20:25),
                    prot3 = c(45:50))                 

p_recipe <- recipe(G ~ ., data = train) %>% 
  step_zv(all_numeric(), -all_outcomes()) 

lasso <- logistic_reg(mixture = 0.5,penalty=0.5) %>% 
  set_engine("glmnet") %>% 
  set_mode("classification") 

lasso_wf <- workflow() %>%
  add_recipe(p_recipe)

lasso_fit <- lasso_wf %>%
  add_model(lasso) %>%
  fit(data = train)

lasso_tun<- logistic_reg( mixture = tune(),penalty=tune()) %>% 
  set_engine("glmnet") %>% 
  set_mode("classification") 

# Define the search grid for hyperparameter tuning 
lasso_grid <- grid_regular( penalty(), mixture(),levels = 10) 

# Tune the hyperparameters using split sample
lasso_res <- tune_grid( lasso_wf %>% 
                          add_model(lasso_tun), resamples=apparent(train),
                        grid = lasso_grid,control=control_grid(parallel_over="everything"))


# Get the best performing model 
lowest_auc <- lasso_res %>%
  select_best("roc_auc")

lasso_model_tun <- finalize_workflow(
  lasso_wf %>% add_model(lasso_tun),
  lowest_auc
)%>%  fit(data = train)

final<-lasso_model_tun%>%extract_fit_parsnip() %>% 
  tidy()

###Predictions
lasso_pred_tun <- as.matrix(predict(lasso_model_tun, test,type = "prob"))[,".pred_D"] 

Upvotes: 0

Views: 45

Answers (0)

Related Questions