Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbkunst/0cfc5ce2d77f0fd50aae16b693fc80ec to your computer and use it in GitHub Desktop.
Save jbkunst/0cfc5ce2d77f0fd50aae16b693fc80ec to your computer and use it in GitHub Desktop.
library(ranger)
data("mtcars")
regularized_rf <- ranger(mpg ~ .,
data = mtcars,
num.trees = 500,
# num.threads = 1, # needs to be set to
# avoid parallelization
mtry = 7,
importance = "impurity",
regularization.factor = 0.3)
standard_rf <- ranger(mpg ~ .,
num.trees = 500,
data = mtcars,
importance = "impurity",
mtry = 7)
# Prediction errors
regularized_rf$prediction.error
standard_rf$prediction.error
# Check variable importance
as.data.frame(importance(regularized_rf))
as.data.frame(importance(standard_rf))
# 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