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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。