I'm receiving the error "in finalize_workflow(., lr_best): object 'lr_wf' not found
I'm running:
R version 4.0.5,
R Studio Version 1.4.1106,
and tidymodels with the developer versions of broom, recipes, and workflows.
Assistance is greatly appreciated, reprex is as follows:
library(tidyverse)
library(tidymodels)
dfin=read_csv(file = "C:/Users/vanwag3/OneDrive - UW/Documents/UW_PhD/PhD_Research/Code_from_Drought_Drive/Drought_Analysis_RCode/LR_NAIP_wCE.csv")
#>
#> -- Column specification --------------------------------------------------------
#> cols(
#> .default = col_double(),
#> neon2017 = col_character()
#> )
#> i Use `spec()` for the full column specifications.
df=dfin %>% mutate(neon2017=factor(neon2017))
set.seed(111)
s_split2=initial_split(df, strata = neon2017)
train_data2=training(s_split2)
test_data2=testing(s_split2)
library(themis)
#> Registered S3 methods overwritten by 'themis':
#> method from
#> bake.step_downsample recipes
#> bake.step_upsample recipes
#> prep.step_downsample recipes
#> prep.step_upsample recipes
#> tidy.step_downsample recipes
#> tidy.step_upsample recipes
#> tunable.step_downsample recipes
#> tunable.step_upsample recipes
#>
#> Attaching package: 'themis'
#> The following objects are masked from 'package:recipes':
#>
#> step_downsample, step_upsample
train_rec2=recipe(neon2017 ~ ., data = train_data2) %>%
update_role(basin_id, new_role="Id")%>%
step_naomit(all_predictors(), skip = TRUE) %>%
step_normalize(all_predictors(), -all_outcomes()) %>%
step_smote(neon2017)
tree_prep2=prep(train_rec2)
juiced2=juice(tree_prep2)
#Cross Validation Folds/Resamples
lr_cv=vfold_cv(train_data2, repeats = 10)
#Specify the Logistic model with the GLMNET engine
lr_mod=
logistic_reg(penalty = tune(), mixture = 1) %>%
set_engine("glmnet") %>%
set_mode("classification")
lr_wflow=
workflow() %>%
add_model(lr_mod) %>%
add_recipe(train_rec2)
#Set the grid for the l.r.
lr_reg_grid <- tibble(penalty = 10^seq(-5,-1, length.out = 30))
#and train the model and tune the parameters
lr_best =
lr_wflow %>%
tune_grid(resamples=lr_cv,
grid = lr_reg_grid,
control = control_grid(save_pred = TRUE),
metrics = metric_set(accuracy, kap,
mcc, roc_auc
)) %>%
select_best("roc_auc")
lr_best
#> # A tibble: 1 x 2
#> penalty .config
#> <dbl> <chr>
#> 1 0.00117 Preprocessor1_Model16
library(workflows)
library(broom)
lr_wf %>%
finalize_workflow(lr_best) %>%
fit(train_data2) %>%
pull_workflow_fit() %>%
tidy()
#> Error in finalize_workflow(., lr_best): object 'lr_wf' not found