我总是完成我的模型来拟合和预测,而不使用prep()、bake()或juice():
rec_wflow <-
workflow() %>%
add_model(lr_mod) %>%
add_recipe(rec)
data_fit <-
rec_wflow %>%
fit(data = train_data)
Run Code Online (Sandbox Code Playgroud)
这些 ( prep, bake, juice) 函数是否仅用于直观地检查数据的预处理结果,而不是拟合/训练过程所必需的?
R包“recipes”中的prep/bake/juice有什么区别?
上面的代码是我在官方教程中学习的。
我在另一篇博客中读到,如果使用train_data,就会产生数据泄漏。我想听听更多相关信息;这些功能是否与数据泄露有关?
我有以下代码,其中我对不同的 mtry 和 min_n 进行一些网格搜索。我知道如何提取提供最高准确度的参数(请参阅第二个代码框)。如何提取训练数据集中每个特征的重要性?我在网上找到的指南显示了如何使用“last_fit”仅在测试数据集中执行此操作。例如指南:https: //www.tidymodels.org/start/case-study/#data-split
set.seed(seed_number)
data_split <- initial_split(node_strength,prop = 0.8,strata = Group)
train <- training(data_split)
test <- testing(data_split)
train_folds <- vfold_cv(train,v = 10)
rfc <- rand_forest(mode = "classification", mtry = tune(),
min_n = tune(), trees = 1500) %>%
set_engine("ranger", num.threads = 48, importance = "impurity")
rfc_recipe <- recipe(data = train, Group~.)
rfc_workflow <- workflow() %>% add_model(rfc) %>%
add_recipe(rfc_recipe)
rfc_result <- rfc_workflow %>%
tune_grid(train_folds, grid = 40, control = control_grid(save_pred = TRUE),
metrics = metric_set(accuracy))
Run Code Online (Sandbox Code Playgroud)
。
best <-
rfc_result …Run Code Online (Sandbox Code Playgroud) 我正在使用tidymodels进行机器学习,我想预测二元响应/结果。如何指定哪个级别的结果是“事件”或积极案例?
这种情况发生在食谱中还是其他地方?
##split the data
anxiety_split <- initial_split(anxiety_df, strata = anxiety)
anxiety_train <- training(anxiety_split)
anxiety_test <- testing(anxiety_split)
set.seed(1222)
anxiety_cv <- vfold_cv(anxiety_train, strata = anxiety)
anxiety_rec <- recipe(anxiety ~ ., data = anxiety_train, positive = 'pos') %>%
step_corr(all_numeric()) %>%
step_dummy(all_nominal(), -all_outcomes()) %>%
step_zv(all_numeric()) %>%
step_normalize(all_numeric())
Run Code Online (Sandbox Code Playgroud)