Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up calculate_tree_depth() #35

Merged
merged 2 commits into from
Mar 11, 2024

Conversation

mayer79
Copy link
Contributor

@mayer79 mayer79 commented Mar 5, 2024

This PR speeds up the node depth calculations, see below for some results pre and post change. As such, it helps to solve #34

library(randomForest)
library(ranger)
library(randomForestExplainer)

set.seed(12)

fit <- randomForest(Sepal.Width~., data = iris)
fit2 <- ranger(Sepal.Width~., data = iris)

system.time(  # 6.25 seconds -> 2.0 seconds
  out <- min_depth_distribution(fit)
)
head(out)
#   tree     variable minimal_depth
# 1    1 Petal.Length             0
# 2    1  Petal.Width             3
# 3    1 Sepal.Length             5
# 4    1      Species             3
# 5    2 Petal.Length             3
# 6    2  Petal.Width             1

system.time(  # 4.8 seconds -> 0.70 seconds
  out <- min_depth_distribution(fit2)
)
head(out)
#   tree     variable minimal_depth
# 1    1 Petal.Length             0
# 2    1  Petal.Width             1
# 3    1 Sepal.Length             1
# 4    1      Species             3
# 5    2 Petal.Length             1
# 6    2  Petal.Width             1

You can test it via

remotes::install_github("ModelOriented/randomForestExplainer", ref = remotes::github_pull(35))

@mayer79 mayer79 requested a review from hbaniecki March 11, 2024 09:43
@mayer79 mayer79 self-assigned this Mar 11, 2024
@hbaniecki
Copy link
Member

thanks

@hbaniecki hbaniecki requested a review from pbiecek March 11, 2024 09:59
@pbiecek
Copy link
Member

pbiecek commented Mar 11, 2024

@mayer79 awesome! thanks

@pbiecek pbiecek merged commit dcacb6b into ModelOriented:master Mar 11, 2024
5 checks passed
@mayer79 mayer79 deleted the tree-depth-faster branch March 14, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants