Partitioning and root node of a binary decision tree (CART)

How to find the separation and root of a node in a regression tree, I created a regression tree from several vectors, now I need to extract the root node from rpart from several vectors. file contains the numerical value of several vectors A , B , C , D , E , F , G , H ex. The vector contains 4,3,6,7,2,4,5, ... etc. Similar to other B, C, D, E, F, G, H. It is also necessary to extract F (which is the root node in my case) as the output of this input after creating the .thank tree you.sorry cannot put any image: (

Here is what I have done so far

 log_data <- read.csv(file="C:\\Users\\AASHU\\Desktop\\CART\\syn.csv", header=T, as.is=T) library(rpart) fit <- rpart(A ~ B+C+D+E+F+G+H, log_data) # plot(fit) plot(fit, compress=TRUE, branch=0) text(fit, xpd = NA, cex = 0.7) summary(fit) Call: rpart(formula = A ~ B + C + D + E + F + G + H, data = log_data) n=52 (1 observation deleted due to missingness) CP nsplit rel error xerror xstd 1 0.09798662 0 1.0000000 1.065250 0.1888568 2 0.09347624 1 0.9020134 1.198999 0.1842667 3 0.03632980 2 0.8085371 1.154558 0.1859743 4 0.02297130 3 0.7722073 1.254874 0.2029423 5 0.01000000 4 0.7492360 1.274024 0.2118272 Node number 1: 52 observations, complexity param=0.09798662 mean=4.403846, MSE=1.509985 left son=2 (7 obs) right son=3 (45 obs) Primary splits: F < 5.5 to the right, improve=0.09798662, (0 missing) 

........... Now I need to extract root node F(F>=5.5) from fit (regression tree) and split it, can anyone help me?

+4
source share
1 answer

find the lables of this tree so that we can extract any of the vectors

when the root of a node is a character (example-A)

 nodes<-labels(fit, digits=4, minlength=1L, pretty, collapse=TRUE) root<-substr(nodes[2], 1, 1) 

from the path we can extract the root of the node tree, below one it is best to extract the name root node, passing its second split, which is nothing more than the root of the node.

 nodes<-labels(fit, digits=4, minlength=1L, pretty, collapse=TRUE) path<-path.rpart(fit, node_no, pretty=0, print.it=FALSE) path[[2]][1] 
+4
source

Source: https://habr.com/ru/post/1441281/


All Articles