Cross Validated
2022-11-27 15:03 UTC
By ebrahimi
AI-113-20221127-social-media-d6d1f49a
How to compute the decrease in impurity in tree regression?
I fitted a regression tree using rpart function. The summary of this model is provided below. I need to know how to calculate the decrease in impurity in each node. For example, in the node number 1, how to obtain improve=0.27435110? What about improve=0.14323610 in the node number 2? Code: library(ISLR) set.seed(123456) n=nrow(Carseats) id.train=sample(1:n,size=300) id.test=setdiff(1:n,id.train) Carseat.train=Carseats[id.train,] Carseat.test=Carseats[id.test,] library(rpart) library(rpart.plot) mytree.reg = rpart(Sales~., data=Carseat.train, method = "anova") prp(mytree.reg,extra=1,roundint=FALSE) mytree.reg summary(mytree.reg) Output: Call: rpart(formula = Sales ~ ., data = Carseat.train, method = "anova") n= 300 CP nsplit rel error xerror xstd 1 0.27435112 0 1.0000000 1.0077435 0.08255353 2 0.07959254 1 0.7256489 0.7325355 0.05989956 3 0.06932427 2 0.6460563 0.7087161 0.05668191 4 0.05309323 3 0.5767321 0.6872537 0.05329518 5 0.03058940 4 0.5236388 0.6127103 0.04785196 6 0.03047785 5 0.4930494 0.6107188 0.04421544 7 0.02891278 6 0.4625716 0.6107188 0.04421544 8 0.02703786 7 0.4336588 0.6072395 0.04438192 9 0.02355029 8 0.4066209 0.5940172 0.04378300 10 0.01570255 9 0.3830707 0.5828484 0.04188387 11 0.01535808 10 0.3673681 0.5426513 0.03687337 12 0.01208271 11 0.3520100 0.5396221 0.03685969 13 0.01112882 12 0.3399273 0.5461840 0.03856361 14 0.01000000 13 0.3287985 0.5396450 0.03957813 Variable importance ShelveLoc Price CompPrice Age Advertising Income Population Education…
I fitted a regression tree using rpart function. The summary of this model is provided below. I need to know how to calculate the decrease in impurity in each node. For example, in the node number 1, how to obtain improve=0.27435110? What about improve=0.14323610 in the node number 2? Code: library(ISLR) set.seed(123456) n=nrow(Carseats) id.train=sample(1:n,size=300) id.test=setdiff(1:n,id.train) Carseat.train=Carseats[id.train,] Carseat.test=Carseats[id.test,] library(rpart) library(rpart.plot) mytree.reg = rpart(Sales~., data=Carseat.train, method = "anova") prp(mytree.reg,extra=1,roundint=FALSE) mytree.reg summary(mytree.reg) Output: Call: rpart(formula = Sales ~ ., data = Carseat.train, method = "anova") n= 300 CP nsplit rel error xerror xstd 1 0.27435112 0 1.0000000 1.0077435 0.08255353 2 0.07959254 1 0.7256489 0.7325355 0.05989956 3 0.06932427 2 0.6460563 0.7087161 0.05668191 4 0.05309323 3 0.5767321 0.6872537 0.05329518 5 0.03058940 4 0.5236388 0.6127103 0.04785196 6 0.03047785 5 0.4930494 0.6107188 0.04421544 7 0.02891278 6 0.4625716 0.6107188 0.04421544 8 0.02703786 7 0.4336588 0.6072395 0.04438192 9 0.02355029 8 0.4066209 0.5940172 0.04378300 10 0.01570255 9 0.3830707 0.5828484 0.04188387 11 0.01535808 10 0.3673681 0.5426513 0.03687337 12 0.01208271 11 0.3520100 0.5396221 0.03685969 13 0.01112882 12 0.3399273 0.5461840 0.03856361 14 0.01000000 13 0.3287985 0.5396450 0.03957813 Variable importance ShelveLoc Price CompPrice Age Advertising Income Population Education…
Full article content could not be extracted automatically. Read the original below.
Source:
Cross Validated
· stats.stackexchange.com