Learn R Programming

butcher (version 0.3.5)

axe-randomForest: Axing an randomForest.

Description

randomForest objects are created from the randomForest package, which is used to train random forests based on Breiman's 2001 work. The package supports ensembles of classification and regression trees.

Usage

# 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, ...)

Value

Axed randomForest object.

Arguments

x

A model object.

verbose

Print information each time an axe method is executed. Notes how much memory is released and what functions are disabled. Default is FALSE.

...

Any additional arguments related to axing.

Examples

Run this code
# Load libraries
library(parsnip)
library(rsample)
library(randomForest)
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)

# 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)

# Check size
lobstr::obj_size(cleaned_rf)

Run the code above in your browser using DataLab