我是 R 的新手,正在尝试学习 tidymodels。
我仅在使用 glm
处理 iris 数据集
时遇到此错误,如果我更换数据集
和配方,那么 glm
运行正常,但随后我在 kknn
中开始遇到此错误。
警告信息:"所有模型在 [fit_resamples()] 中失败。请查看 `.notes` 列。"警告信息:"此调优结果有注释。关于模型拟合的示例注释包括:内部: 错误: 在指标: `roc_auc`
我检查了 .notes
,看起来是这样的:
.notes<chr>内部: 错误: 在指标: `roc_auc`A tibble: 1 × 1 .notes<chr>内部: 错误: 在指标: `roc_auc`A tibble: 1 × 1
警告信息: 所有模型在 [fit_resamples()] 中失败。请查看 `.notes` 列
正如上面帖子中建议的那样,我尝试从 GitHub 升级 parsnip
和 tune
包,但在安装 tune 包
时遇到错误: 警告在 install.packages 中: 包‘tune’在当前版本的 R 中不可用
我不确定哪里出了问题,如果有人能帮助我将不胜感激!!!
版本信息:
-- 附加包 --------------------------------------- tidyverse 1.3.0 --v ggplot2 3.3.2 v purrr 0.3.4v tibble 3.0.4 v dplyr 1.0.2v tidyr 1.1.2 v stringr 1.4.0v readr 1.4.0 v forcats 0.5.0-- 冲突 ------------------------------------------ tidyverse_conflicts() --x dplyr::filter() masks stats::filter()x dplyr::lag() masks stats::lag()-- 附加包 -------------------------------------- tidymodels 0.1.1 --v broom 0.7.2 v recipes 0.1.14 v dials 0.0.9 v rsample 0.0.8 v infer 0.5.3 v tune 0.1.1 v modeldata 0.0.2 v workflows 0.2.1 v parsnip 0.1.3.9000 v yardstick 0.0.7 -- 冲突 ----------------------------------------- tidymodels_conflicts() --x scales::discard() masks purrr::discard()x dplyr::filter() masks stats::filter()x recipes::fixed() masks stringr::fixed()x dplyr::lag() masks stats::lag()x yardstick::spec() masks readr::spec()x recipes::step() masks stats::step()Windows 7platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 4 minor 0.3 year 2020 month 10 day 10 svn rev 79318 language R version.string R version 4.0.3 (2020-10-10)
代码:
library(tidyverse)library(tidymodels)library(themis)iris# 数据分割set.seed(999)iris_split <- initial_split(iris, strata = Species)iris_train <- training(iris_split)iris_test <- testing(iris_split)# 交叉验证set.seed(345)iris_fold <- vfold_cv(iris_train)print(iris_fold)# 配方iris_rec <- recipe(Species ~., data = iris_train) %>% #确保训练集中的目标变量数量相等(对于 iris 数据集不需要) step_downsample(Species) %>% #标准化数据 step_center(-Species) %>% step_scale(-Species) %>% step_BoxCox(-Species) %>% #应用配方到数据的函数 prep()# 工作流程iris_wf <- workflow() %>% add_recipe(iris_rec)# 逻辑回归glm_spec <- logistic_reg() %>% set_engine("glm")# 进行并行处理doParallel::registerDoParallel()# 添加参数到工作流程glm_rs <- iris_wf %>% add_model(glm_spec) %>% fit_resamples( resamples = iris_fold, metrics = metric_set(roc_auc, accuracy, sensitivity, specificity), control = control_resamples(save_pred = TRUE) )
错误
警告信息:"所有模型在 [fit_resamples()] 中失败。请查看 `.notes` 列。"警告信息:"此调优结果有注释。关于模型拟合的示例注释包括:内部: 错误: 在指标: `roc_auc`内部: 错误: 在指标: `roc_auc`内部: 错误: 在指标: `roc_auc`"# 重抽样结果# 10折交叉验证 # A tibble: 10 x 5 splits id .metrics .notes .predictions <list> <chr> <list> <list> <list> 1 <split [102/12]> Fold01 <NULL> <tibble [1 x 1]> <NULL> 2 <split [102/12]> Fold02 <NULL> <tibble [1 x 1]> <NULL> 3 <split [102/12]> Fold03 <NULL> <tibble [1 x 1]> <NULL> 4 <split [102/12]> Fold04 <NULL> <tibble [1 x 1]> <NULL> 5 <split [103/11]> Fold05 <NULL> <tibble [1 x 1]> <NULL> 6 <split [103/11]> Fold06 <NULL> <tibble [1 x 1]> <NULL> 7 <split [103/11]> Fold07 <NULL> <tibble [1 x 1]> <NULL> 8 <split [103/11]> Fold08 <NULL> <tibble [1 x 1]> <NULL> 9 <split [103/11]> Fold09 <NULL> <tibble [1 x 1]> <NULL> 10 <split [103/11]> Fold10 <NULL> <tibble [1 x 1]> <NULL>
(更新)
即使不使用 Parallel
计算,也会在 RF
中遇到错误
回答:
我在 Linux 机器上也遇到了同样的问题,但通过删除 NA 或对其进行插补解决了问题。所以,看来 NA 的存在导致了模型拟合失败!:)