I employed RPart to build a decision tree. Without a problem, I am doing this. But, I need to learn (or count) how many times the tree has been splitted? I mean, how many rules (if-else statement) the tree has? For instance:
X
- -
if (a<9)- - if(a>=9)
Y H
-
if(b>2)-
Z
There are 3 rules.
When I write summary(model):
summary(model_dt)
Call:
rpart(formula = Alert ~ ., data = train)
n= 18576811
CP nsplit rel error xerror xstd
1 0.9597394 0 1.00000000 1.00000000 0.0012360956
2 0.0100000 1 0.04026061 0.05290522 0.0002890205
Variable importance
ip.src frame.protocols tcp.flags.ack tcp.flags.reset frame.len
20 17 17 17 16
ip.ttl
` 12
Node number 1: 18576811 observations, complexity param=0.9597394
predicted class=yes expected loss=0.034032 P(node) =1
class counts: 632206 1.79446e+07
probabilities: 0.034 0.966
left son=2 (627091 obs) right son=3 (17949720 obs)
Primary splits:
ip.src splits as LLLLLLLRRRLLRR ............ LLRLRLRRRRRRRRRRRRRRRR
improve=1170831.0, (0 missing)
ip.dts splits as LLLLLLLLLLLLLLLLLLLRLLLLLLLLLLL, improve=1013082.0, (0 missing)
tcp.flags.ctl < 1.5 to the right, improve=1007953.0, (2645 missing)
tcp.flags.syn < 1.5 to the right, improve=1007953.0, (2645 missing)
frame.len < 68 to the right, improve= 972871.3, (30 missing)
Surrogate splits:
frame.protocols splits as LLLLLLLLLLLLLLLLLLLRLLLLLLLLLLL, agree=0.995, adj=0.841, (0 split)
tcp.flags.ack < 1.5 to the right, agree=0.994, adj=0.836, (0 split)
tcp.flags.reset < 1.5 to the right, agree=0.994, adj=0.836, (0 split)
frame.len < 68 to the right, agree=0.994, adj=0.809, (0 split)
ip.ttl < 230.5 to the right, agree=0.987, adj=0.612, (0 split)
Node number 2: 627091 observations
predicted class=no expected loss=0.01621615 P(node) =0.03375666
class counts: 616922 10169
probabilities: 0.984 0.016
Node number 3: 17949720 observations
predicted class=yes expected loss=0.0008514896 P(node) =0.9662433
class counts: 15284 1.79344e+07
probabilities: 0.001 0.999
If anyone helps me to understand it, I will be grateful
SIncerely Eray