这些函数从防风草对象中提取各种元素。如果它们尚不存在,则会抛出错误。
-
extract_spec_parsnip()
返回防风草模型规范。 -
extract_fit_engine()
返回嵌入防风草模型拟合中的引擎特定拟合。例如,当将linear_reg()
与"lm"
引擎一起使用时,这将返回底层lm
对象。 -
extract_parameter_dials()
返回单个拨号参数对象。 -
extract_parameter_set_dials()
返回一组拨号参数对象。
用法
# S3 method for model_fit
extract_spec_parsnip(x, ...)
# S3 method for model_fit
extract_fit_engine(x, ...)
# S3 method for model_spec
extract_parameter_set_dials(x, ...)
# S3 method for model_spec
extract_parameter_dials(x, parameter, ...)
细节
提取底层引擎拟合有助于说明模型(通过 print()
、 summary()
、 plot()
等)或变量重要性/解释器。
但是,用户不应在提取的模型上调用predict()
方法。 parsnip
在将数据提供给模型之前可能已对数据执行了预处理操作。绕过这些可能会导致错误或默默地生成不正确的预测。
好的:
parsnip_fit %>% predict(new_data)
坏的:
parsnip_fit %>% extract_fit_engine() %>% predict(new_data)
例子
lm_spec <- linear_reg() %>% set_engine("lm")
lm_fit <- fit(lm_spec, mpg ~ ., data = mtcars)
lm_spec
#> Linear Regression Model Specification (regression)
#>
#> Computational engine: lm
#>
extract_spec_parsnip(lm_fit)
#> Linear Regression Model Specification (regression)
#>
#> Computational engine: lm
#>
#> Model fit template:
#> stats::lm(formula = missing_arg(), data = missing_arg(), weights = missing_arg())
extract_fit_engine(lm_fit)
#>
#> Call:
#> stats::lm(formula = mpg ~ ., data = data)
#>
#> Coefficients:
#> (Intercept) cyl disp hp drat
#> 12.30337 -0.11144 0.01334 -0.02148 0.78711
#> wt qsec vs am gear
#> -3.71530 0.82104 0.31776 2.52023 0.65541
#> carb
#> -0.19942
#>
lm(mpg ~ ., data = mtcars)
#>
#> Call:
#> lm(formula = mpg ~ ., data = mtcars)
#>
#> Coefficients:
#> (Intercept) cyl disp hp drat
#> 12.30337 -0.11144 0.01334 -0.02148 0.78711
#> wt qsec vs am gear
#> -3.71530 0.82104 0.31776 2.52023 0.65541
#> carb
#> -0.19942
#>
相关用法
- 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 repair_call 修复模型调用对象
- R parsnip dot-model_param_name_key 翻译模型调整参数的名称
- R parsnip glm_grouped 将数据集中的分组二项式结果与个案权重拟合
- R parsnip rule_fit 规则拟合模型
- 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 rand_forest 随机森林
- 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等大神的英文原创作品 Extract elements of a parsnip model object。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。