step_percentile()
創建配方步驟的規範,用訓練集中的百分位數替換變量的值。
用法
step_percentile(
recipe,
...,
role = NA,
trained = FALSE,
ref_dist = NULL,
options = list(probs = (0:100)/100),
outside = "none",
skip = FALSE,
id = rand_id("percentile")
)
參數
- recipe
-
一個菜譜對象。該步驟將添加到此配方的操作序列中。
- ...
-
一個或多個選擇器函數用於為此步驟選擇變量。有關更多詳細信息,請參閱
selections()
。 - role
-
對於此步驟創建的模型項,應為其分配什麽分析角色?默認情況下,此步驟根據原始變量創建的新列將用作模型中的預測變量。
- trained
-
指示預處理數量是否已估計的邏輯。
- ref_dist
-
一旦
prep()
訓練了該預處理步驟,計算出的百分位數就會存儲在此處。 - options
-
要傳遞給
stats::quantile()
的命名選項列表。請參閱詳細信息了解更多信息。 - outside
-
一個字符,說明如何在區間
[min(x), max(x)]
之外進行插值。none
意味著什麽都不會發生,超出範圍的值將為NA
。lower
意味著小於min(x)
的新值將被賦予值0
。upper
意味著大於max(x)
的新值將被賦予值1
。both
將處理這兩種情況。默認為none
。 - skip
-
一個合乎邏輯的。當
bake()
烘焙食譜時是否應該跳過此步驟?雖然所有操作都是在prep()
運行時烘焙的,但某些操作可能無法對新數據進行(例如處理結果變量)。使用skip = TRUE
時應小心,因為它可能會影響後續操作的計算。 - id
-
該步驟特有的字符串,用於標識它。
箱重
此步驟執行可以利用案例權重的無監督操作。因此,個案權重僅與頻率權重一起使用。有關更多信息,請參閱 case_weights 中的文檔和 tidymodels.org
中的示例。
也可以看看
其他單獨的轉換步驟:step_BoxCox()
, step_YeoJohnson()
, step_bs()
, step_harmonic()
, step_hyperbolic()
, step_inverse()
, step_invlogit()
, step_logit()
, step_log()
, step_mutate()
, step_ns()
, step_poly()
, step_relu()
, step_sqrt()
例子
data(biomass, package = "modeldata")
biomass_tr <- biomass[biomass$dataset == "Training", ]
biomass_te <- biomass[biomass$dataset == "Testing", ]
rec <- recipe(
HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
data = biomass_tr
) %>%
step_percentile(carbon)
prepped_rec <- prep(rec)
prepped_rec %>%
bake(biomass_te)
#> # A tibble: 80 × 6
#> carbon hydrogen oxygen nitrogen sulfur HHV
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.421 5.67 47.2 0.3 0.22 18.3
#> 2 0.18 5.5 48.1 2.85 0.34 17.6
#> 3 0.156 5.5 49.1 2.4 0.3 17.2
#> 4 0.423 6.1 37.3 1.8 0.5 18.9
#> 5 0.666 6.32 42.8 0.2 0 20.5
#> 6 0.218 5.5 41.7 0.7 0.2 18.5
#> 7 0.0803 5.23 54.1 1.19 0.51 15.1
#> 8 0.139 4.66 33.8 0.95 0.2 16.2
#> 9 0.0226 4.4 31.1 0.14 4.9 11.1
#> 10 0.0178 3.77 23.7 4.63 1.05 10.8
#> # ℹ 70 more rows
tidy(rec, 1)
#> # A tibble: 1 × 4
#> terms value percentile id
#> <chr> <dbl> <dbl> <chr>
#> 1 carbon NA NA percentile_dwNDP
tidy(prepped_rec, 1)
#> # A tibble: 101 × 4
#> term value percentile id
#> <chr> <dbl> <dbl> <chr>
#> 1 carbon 14.6 0 percentile_dwNDP
#> 2 carbon 25.9 1 percentile_dwNDP
#> 3 carbon 28.4 2 percentile_dwNDP
#> 4 carbon 31.6 3 percentile_dwNDP
#> 5 carbon 35.1 4 percentile_dwNDP
#> 6 carbon 35.9 5 percentile_dwNDP
#> 7 carbon 37.5 6 percentile_dwNDP
#> 8 carbon 38.3 7 percentile_dwNDP
#> 9 carbon 38.9 8 percentile_dwNDP
#> 10 carbon 39.6 9 percentile_dwNDP
#> # ℹ 91 more rows
相關用法
- R recipes step_poly_bernstein 廣義伯恩斯坦多項式基
- R recipes step_pls 偏最小二乘特征提取
- R recipes step_profile 創建數據集的分析版本
- R recipes step_pca 主成分分析信號提取
- R recipes step_poly 正交多項式基函數
- R recipes step_unknown 將缺失的類別分配給“未知”
- R recipes step_relu 應用(平滑)修正線性變換
- R recipes step_impute_knn 通過 k 最近鄰進行插補
- R recipes step_impute_mean 使用平均值估算數值數據
- R recipes step_inverse 逆變換
- 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 step_regex 檢測正則表達式
- R recipes step_spline_b 基礎樣條
- R recipes step_window 移動窗口函數
- R recipes step_ica ICA 信號提取
注:本文由純淨天空篩選整理自Max Kuhn等大神的英文原創作品 Percentile Transformation。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。