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


R butcher axe-randomForest 砍掉随机森林。


randomForest 对象是从 randomForest 包创建的,该包用于基于 Breiman 2001 年的工作来训练随机森林。该包支持分类和回归树的集成。

用法

# S3 method for randomForest
axe_call(x, verbose = FALSE, ...)

# S3 method for randomForest
axe_ctrl(x, verbose = FALSE, ...)

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

参数

x

一个模型对象。

verbose

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

...

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

砍掉 randomForest 对象。

例子

# Load libraries
library(parsnip)
library(rsample)
library(randomForest)
#> randomForest 4.7-1.1
#> Type rfNews() to see new features/changes/bug fixes.
#> 
#> Attaching package: ‘randomForest’
#> The following object is masked from ‘package:ggplot2’:
#> 
#>     margin
data(kyphosis, package = "rpart")

# Load data
set.seed(1234)
split <- initial_split(kyphosis, prop = 9/10)
spine_train <- training(split)

# Create model and fit
randomForest_fit <- rand_forest(mode = "classification",
                                mtry = 2,
                                trees = 2,
                                min_n = 3) %>%
  set_engine("randomForest") %>%
  fit_xy(x = spine_train[,2:4], y = spine_train$Kyphosis)

out <- butcher(randomForest_fit, verbose = TRUE)
#> ✔ Memory released: 192 B

# Another randomForest object
wrapped_rf <- function() {
  some_junk_in_environment <- runif(1e6)
  randomForest_fit <- randomForest(mpg ~ ., data = mtcars)
  return(randomForest_fit)
}

# Remove junk
cleaned_rf <- axe_env(wrapped_rf(), verbose = TRUE)
#> ✔ Memory released: 8.06 MB

# Check size
lobstr::obj_size(cleaned_rf)
#> 428 kB
源代码:R/randomForest.R

相关用法


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