确定模型所需的包
用法
# S3 method for model_spec
required_pkgs(x, infra = TRUE, ...)
# S3 method for model_fit
required_pkgs(x, infra = TRUE, ...)
例子
should_fail <- try(required_pkgs(linear_reg(engine = NULL)), silent = TRUE)
should_fail
#> [1] "Error in required_pkgs(linear_reg(engine = NULL)) : Please set an engine.\n"
#> attr(,"class")
#> [1] "try-error"
#> attr(,"condition")
#> <error/rlang_error>
#> Error in `required_pkgs()`:
#> ! Please set an engine.
#> ---
#> Backtrace:
#> ▆
#> 1. └─pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
#> 2. └─pkgdown::build_site(...)
#> 3. └─pkgdown:::build_site_local(...)
#> 4. └─pkgdown::build_reference(...)
#> 5. └─purrr::map(...)
#> 6. └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#> 7. ├─purrr:::with_indexed_errors(...)
#> 8. │ └─base::withCallingHandlers(...)
#> 9. ├─purrr:::call_with_cleanup(...)
#> 10. └─pkgdown (local) .f(.x[[i]], ...)
#> 11. ├─base::withCallingHandlers(...)
#> 12. └─pkgdown:::data_reference_topic(...)
#> 13. └─pkgdown:::run_examples(...)
#> 14. └─pkgdown:::highlight_examples(code, topic, env = env)
#> 15. └─downlit::evaluate_and_highlight(...)
#> 16. └─evaluate::evaluate(code, child_env(env), new_device = TRUE, output_handler = output_handler)
#> 17. └─evaluate:::evaluate_call(...)
#> 18. ├─evaluate (local) timing_fn(...)
#> 19. ├─evaluate (local) handle(...)
#> 20. │ └─base::try(f, silent = TRUE)
#> 21. │ └─base::tryCatch(...)
#> 22. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 23. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 24. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 25. ├─base::withCallingHandlers(...)
#> 26. ├─base::withVisible(...)
#> 27. └─evaluate:::eval_with_user_handlers(expr, envir, enclos, user_handlers)
#> 28. └─base::eval(expr, envir, enclos)
#> 29. └─base::eval(expr, envir, enclos)
#> 30. ├─base::try(required_pkgs(linear_reg(engine = NULL)), silent = TRUE)
#> 31. │ └─base::tryCatch(...)
#> 32. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 33. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 34. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 35. ├─generics::required_pkgs(linear_reg(engine = NULL))
#> 36. └─parsnip:::required_pkgs.model_spec(linear_reg(engine = NULL))
linear_reg() %>%
set_engine("glmnet") %>%
required_pkgs()
#> [1] "parsnip" "glmnet"
linear_reg() %>%
set_engine("glmnet") %>%
required_pkgs(infra = FALSE)
#> [1] "glmnet"
linear_reg() %>%
set_engine("lm") %>%
fit(mpg ~ ., data = mtcars) %>%
required_pkgs()
#> [1] "parsnip" "stats"
相关用法
- R parsnip repair_call 修复模型调用对象
- R parsnip rule_fit 规则拟合模型
- R parsnip rand_forest 随机森林
- R parsnip logistic_reg 逻辑回归
- R parsnip predict.model_fit 模型预测
- R parsnip linear_reg 线性回归
- R parsnip C5_rules C5.0 基于规则的分类模型
- R parsnip set_engine 声明计算引擎和特定参数
- R parsnip condense_control 将控制对象压缩为更小的控制对象
- R parsnip control_parsnip 控制拟合函数
- R parsnip augment 通过预测增强数据
- R parsnip dot-model_param_name_key 翻译模型调整参数的名称
- R parsnip glm_grouped 将数据集中的分组二项式结果与个案权重拟合
- R parsnip svm_rbf 径向基函数支持向量机
- R parsnip set_args 更改模型规范的元素
- R parsnip translate 解决计算引擎的模型规范
- R parsnip max_mtry_formula 根据公式确定 mtry 的最大值。此函数可能会根据公式和数据集限制 mtry 的值。对于生存和/或多变量模型来说,这是一种安全的方法。
- R parsnip svm_linear 线性支持向量机
- R parsnip set_new_model 注册模型的工具
- R parsnip mlp 单层神经网络
- R parsnip nearest_neighbor K-最近邻
- R parsnip parsnip_update 更新型号规格
- R parsnip fit 将模型规范拟合到数据集
- R parsnip boost_tree 增强树
- R parsnip bart 贝叶斯加性回归树 (BART)
注:本文由纯净天空筛选整理自Max Kuhn等大神的英文原创作品 Determine required packages for a model。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。