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


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