has_role() 、 all_predictors() 和 all_outcomes() 可用于选择公式中具有特定角色的变量。
在大多数情况下,用户的正确方法是使用 predictor-specific 选择器,例如 all_numeric_predictors() 和 all_nominal_predictors() 。一般来说,如果 *_predictors() 选择器可以执行您想要的操作,则在使用 -all_outcomes() 时应小心。
同样,has_type() , all_numeric() , all_integer() , all_double() , all_nominal() , all_ordered() , all_unordered() , all_factor() , all_string() , all_date() 和 all_datetime() 用于根据数据类型选择列。
all_factor() 捕获有序和无序因子,all_string() 捕获字符,all_unordered() 捕获无序因子和字符,all_ordered() 捕获有序因子,all_nominal() 捕获字符、无序和有序因子。
all_integer() 捕获整数,all_double() 捕获双精度数,all_numeric() 捕获所有类型的数字。
all_date() 捕获Date() 变量,all_datetime() 捕获POSIXct() 变量。
有关详细信息,请参阅selections。
current_info() 是一个内部函数。
除了步骤函数中的列选择之外,所有这些函数的效用都有限。
用法
has_role(match = "predictor")
has_type(match = "numeric")
all_outcomes()
all_predictors()
all_date()
all_date_predictors()
all_datetime()
all_datetime_predictors()
all_double()
all_double_predictors()
all_factor()
all_factor_predictors()
all_integer()
all_integer_predictors()
all_logical()
all_logical_predictors()
all_nominal()
all_nominal_predictors()
all_numeric()
all_numeric_predictors()
all_ordered()
all_ordered_predictors()
all_string()
all_string_predictors()
all_unordered()
all_unordered_predictors()
current_info()
例子
data(biomass, package = "modeldata")
rec <- recipe(biomass) %>%
update_role(
carbon, hydrogen, oxygen, nitrogen, sulfur,
new_role = "predictor"
) %>%
update_role(HHV, new_role = "outcome") %>%
update_role(sample, new_role = "id variable") %>%
update_role(dataset, new_role = "splitting indicator")
recipe_info <- summary(rec)
recipe_info
#> # A tibble: 8 × 4
#> variable type role source
#> <chr> <list> <chr> <chr>
#> 1 sample <chr [3]> id variable original
#> 2 dataset <chr [3]> splitting indicator original
#> 3 carbon <chr [2]> predictor original
#> 4 hydrogen <chr [2]> predictor original
#> 5 oxygen <chr [2]> predictor original
#> 6 nitrogen <chr [2]> predictor original
#> 7 sulfur <chr [2]> predictor original
#> 8 HHV <chr [2]> outcome original
# Centering on all predictors except carbon
rec %>%
step_center(all_predictors(), -carbon) %>%
prep(training = biomass) %>%
bake(new_data = NULL)
#> # A tibble: 536 × 8
#> sample dataset carbon hydrogen oxygen nitrogen sulfur HHV
#> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Akhrot Shell Traini… 49.8 0.181 4.37 -0.667 -0.234 20.0
#> 2 Alabama Oak Wood… Traini… 49.5 0.241 2.73 -0.877 -0.234 19.2
#> 3 Alder Traini… 47.8 0.341 7.68 -0.967 -0.214 18.3
#> 4 Alfalfa Traini… 45.1 -0.489 -2.97 2.22 -0.0736 18.2
#> 5 Alfalfa Seed Str… Traini… 46.8 -0.0586 2.15 -0.0772 -0.214 18.4
#> 6 Alfalfa Stalks Traini… 45.4 0.291 1.63 0.963 -0.134 18.5
#> 7 Alfalfa Stems Traini… 47.2 0.531 -0.383 1.60 -0.0336 18.7
#> 8 Alfalfa Straw Traini… 45.7 0.241 1.13 0.623 -0.0336 18.3
#> 9 Almond Traini… 48.8 0.0414 2.33 -0.277 -0.234 18.6
#> 10 Almond Hull Traini… 47.1 0.441 1.43 0.123 -0.134 18.9
#> # ℹ 526 more rows
相关用法
- 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 update.step 更新菜谱步骤
- 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等大神的英文原创作品 Role Selection。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
