Forked from brunaw/how to use the regularized rf in ranger
Last active
July 29, 2022 14:16
-
-
Save jbkunst/0cfc5ce2d77f0fd50aae16b693fc80ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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