将random forest可视化方法:
(1)对于randomForest()得到的随机森林可视化:
参考:https://shiring.github.io/machine_learning/2017/03/16/rf_plot_ggraph
library(dplyr)
library(ggraph)
library(igraph)
#####################################################################
#https://shiring.github.io/machine_learning/2017/03/16/rf_plot_ggraph
#####################################################################
tree_func <- function(final_model,
tree_num) {
# get tree by index
tree <- randomForest::getTree(final_model,
k = tree_num,
labelVar = TRUE) %>%
tibble::rownames_to_column() %>%
# make leaf split points to NA, so the 0s won't get plotted
mutate(`split point` = ifelse(is.na(prediction),