当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R butcher axe-recipe 砍掉一个配方对象。


配方对象是从创建的食谱包,用于其数据预处理工具集。这些方法通过按顺序定义每个预处理步骤来工作。然而,每个步骤的实现都会产生自己的类,因此我们在这里捆绑与配方对象相关的所有 ax 方法。请注意,屠宰类仅作为一个整体添加到配方中,而不是添加到每个预处理步骤中。

用法

# S3 method for recipe
axe_env(x, verbose = FALSE, ...)

# S3 method for step
axe_env(x, ...)

# S3 method for step_arrange
axe_env(x, ...)

# S3 method for step_filter
axe_env(x, ...)

# S3 method for step_mutate
axe_env(x, ...)

# S3 method for step_slice
axe_env(x, ...)

# S3 method for step_impute_bag
axe_env(x, ...)

# S3 method for step_bagimpute
axe_env(x, ...)

# S3 method for step_impute_knn
axe_env(x, ...)

# S3 method for step_knnimpute
axe_env(x, ...)

# S3 method for step_geodist
axe_env(x, ...)

# S3 method for step_interact
axe_env(x, ...)

# S3 method for step_ratio
axe_env(x, ...)

# S3 method for quosure
axe_env(x, ...)

# S3 method for recipe
axe_fitted(x, verbose = FALSE, ...)

参数

x

一个模型对象。

verbose

每次执行 ax 方法时打印信息。记录释放了多少内存以及禁用了哪些函数。默认为 FALSE

...

与砍伐相关的任何其他参数。

砍掉配方对象。

例子

library(recipes)
#> Loading required package: dplyr
#> 
#> Attaching package: ‘dplyr’
#> The following object is masked from ‘package:randomForest’:
#> 
#>     combine
#> The following object is masked from ‘package:MASS’:
#> 
#>     select
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
#> 
#> Attaching package: ‘recipes’
#> The following object is masked from ‘package:stats’:
#> 
#>     step
data(biomass, package = "modeldata")

biomass_tr <- biomass[biomass$dataset == "Training",]
rec <- recipe(HHV ~ carbon + hydrogen + oxygen + nitrogen + sulfur,
              data = biomass_tr) %>%
  step_center(all_predictors()) %>%
  step_scale(all_predictors()) %>%
  step_spatialsign(all_predictors())

out <- butcher(rec, verbose = TRUE)
#> ✔ Memory released: 68.15 kB

# Another recipe object
wrapped_recipes <- function() {
  some_junk_in_environment <- runif(1e6)
  return(
    recipe(mpg ~ cyl, data = mtcars) %>%
      step_center(all_predictors()) %>%
      step_scale(all_predictors()) %>%
      prep()
  )
}

# Remove junk in environment
cleaned1 <- axe_env(wrapped_recipes(), verbose = TRUE)
#> ✔ Memory released: 8.11 MB
# Replace prepared training data with zero-row slice
cleaned2 <- axe_fitted(wrapped_recipes(), verbose = TRUE)
#> ✔ Memory released: 296 B

# Check size
lobstr::obj_size(cleaned1)
#> 13.09 kB
lobstr::obj_size(cleaned2)
#> 8.02 MB
源代码:R/recipe.R

相关用法


注:本文由纯净天空筛选整理自Davis Vaughan等大神的英文原创作品 Axing a recipe object.。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。