Skip to content

Instantly share code, notes, and snippets.

@brunaw
Last active July 29, 2022 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brunaw/25aedf69fc324c6311b77448b617f630 to your computer and use it in GitHub Desktop.
Save brunaw/25aedf69fc324c6311b77448b617f630 to your computer and use it in GitHub Desktop.
devtools::install_github("imbs-hl/ranger")
library(ranger)
data("mtcars")
regularized_rf <- ranger(mpg ~ .,
data = mtcars,
num.trees = 100,
num.threads = 1, # needs to be set to
# avoid parallelization
mtry = 7,
regularization.factor = 0.3)
standard_rf <- ranger(mpg ~ .,
num.trees = 100,
data = mtcars,
mtry = 7)
# Prediction errors
regularized_rf$prediction.error
standard_rf$prediction.error
# Number of variables used
length(unique(unlist(regularized_rf$forest$split.varIDs)))
length(unique(unlist(standard_rf$forest$split.varIDs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment