update()
的 step
方法采用命名参数作为 ...
,其值将替换实际步骤中的同名元素。
例子
data(biomass, package = "modeldata")
biomass_tr <- biomass[biomass$dataset == "Training", ]
biomass_te <- biomass[biomass$dataset == "Testing", ]
# Create a recipe using step_bs() with degree = 3
rec <- recipe(
HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
data = biomass_tr
) %>%
step_bs(carbon, hydrogen, degree = 3)
# Update the step to use degree = 4
rec2 <- rec
rec2$steps[[1]] <- update(rec2$steps[[1]], degree = 4)
# Prep both recipes
rec_prepped <- prep(rec, training = biomass_tr)
rec2_prepped <- prep(rec2, training = biomass_tr)
# To see what changed
bake(rec_prepped, new_data = NULL)
#> # A tibble: 456 × 10
#> oxygen nitrogen sulfur HHV carbon_bs_1 carbon_bs_2 carbon_bs_3
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 42.9 0.41 0 20.0 0.421 0.313 0.0775
#> 2 41.3 0.2 0 19.2 0.423 0.309 0.0754
#> 3 46.2 0.11 0.02 18.3 0.431 0.290 0.0651
#> 4 35.6 3.3 0.16 18.2 0.441 0.258 0.0504
#> 5 40.7 1 0.02 18.4 0.436 0.278 0.0590
#> 6 40.2 2.04 0.1 18.5 0.440 0.262 0.0519
#> 7 38.2 2.68 0.2 18.7 0.434 0.283 0.0613
#> 8 39.7 1.7 0.2 18.3 0.439 0.265 0.0534
#> 9 40.9 0.8 0 18.6 0.426 0.301 0.0710
#> 10 40 1.2 0.1 18.9 0.434 0.282 0.0609
#> # ℹ 446 more rows
#> # ℹ 3 more variables: hydrogen_bs_1 <dbl>, hydrogen_bs_2 <dbl>,
#> # hydrogen_bs_3 <dbl>
bake(rec2_prepped, new_data = NULL)
#> # A tibble: 456 × 12
#> oxygen nitrogen sulfur HHV carbon_bs_1 carbon_bs_2 carbon_bs_3
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 42.9 0.41 0 20.0 0.322 0.359 0.178
#> 2 41.3 0.2 0 19.2 0.325 0.357 0.174
#> 3 46.2 0.11 0.02 18.3 0.344 0.347 0.156
#> 4 35.6 3.3 0.16 18.2 0.371 0.325 0.127
#> 5 40.7 1 0.02 18.4 0.355 0.339 0.144
#> 6 40.2 2.04 0.1 18.5 0.368 0.328 0.130
#> 7 38.2 2.68 0.2 18.7 0.350 0.342 0.149
#> 8 39.7 1.7 0.2 18.3 0.365 0.331 0.133
#> 9 40.9 0.8 0 18.6 0.333 0.353 0.166
#> 10 40 1.2 0.1 18.9 0.351 0.342 0.148
#> # ℹ 446 more rows
#> # ℹ 5 more variables: carbon_bs_4 <dbl>, hydrogen_bs_1 <dbl>,
#> # hydrogen_bs_2 <dbl>, hydrogen_bs_3 <dbl>, hydrogen_bs_4 <dbl>
# Cannot update a recipe step that has been trained!
if (FALSE) {
update(rec_prepped$steps[[1]], degree = 4)
}
相关用法
- R recipes update_role_requirements 更新角色特定要求
- R recipes step_unknown 将缺失的类别分配给“未知”
- R recipes step_relu 应用(平滑)修正线性变换
- R recipes step_poly_bernstein 广义伯恩斯坦多项式基
- R recipes step_impute_knn 通过 k 最近邻进行插补
- R recipes step_impute_mean 使用平均值估算数值数据
- R recipes step_inverse 逆变换
- R recipes step_pls 偏最小二乘特征提取
- R recipes step_ratio 比率变量创建
- R recipes step_geodist 两个地点之间的距离
- R recipes step_nzv 近零方差滤波器
- R recipes step_nnmf 非负矩阵分解信号提取
- R recipes step_normalize 中心和比例数值数据
- R recipes step_depth 数据深度
- R recipes step_other 折叠一些分类级别
- R recipes step_harmonic 添加正弦和余弦项以进行谐波分析
- R recipes step_corr 高相关滤波器
- R recipes step_novel 新因子水平的简单赋值
- R recipes step_select 使用 dplyr 选择变量
- R recipes formula.recipe 从准备好的食谱创建配方
- R recipes step_regex 检测正则表达式
- R recipes step_spline_b 基础样条
- R recipes step_window 移动窗口函数
- R recipes step_ica ICA 信号提取
- R recipes check_range 检查范围一致性
注:本文由纯净天空筛选整理自Max Kuhn等大神的英文原创作品 Update a recipe step。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。