Open rogerjdeangelis opened 4 years ago
Hi tidypredict team
I realize the code for just one tree is low priority, but I like to look at the code and the tree diagram to get insight into how randomforest is slicing up the data.
I am a SAS programmer but find myself leaning on tidy and haven packages more and more as time goes on.
Thanks for providing these packages!
Roger
Hi @rogerjdeangelis, what is the issue that you are seeing? I'm not getting any errors.
If what you want to see is the structure of the tree, you could use parse_model()
to get an object that reads the Random Forest model, and breaks it down into a somewhat readable list, here is an example:
library(randomForest)
library(tidypredict)
model <- randomForest(iris$Sepal.Length~ ., data = iris[,2:4], ntree = 1)
parsedmodel <- parse_model(model)
str(parsedmodel$trees)
#> List of 1
#> $ :List of 48
#> ..$ :List of 2
#> .. ..$ prediction: NULL
#> .. ..$ path :List of 3
#> .. .. ..$ :List of 4
#> .. .. .. ..$ type: chr "conditional"
#> .. .. .. ..$ col : chr "Petal.Width"
#> .. .. .. ..$ val : num 1.15
#> .. .. .. ..$ op : chr "less"
#> .. .. ..$ :List of 4
#> .. .. .. ..$ type: chr "conditional"
#> .. .. .. ..$ col : chr "Petal.Length"
#> .. .. .. ..$ val : num 3.4
#> .. .. .. ..$ op : chr "more-equal"
#> .. .. ..$ :List of 4
.... more
Partial listing