當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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