Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rpart node assignment

Is it possible to extract the node assignment for a fitted rpart tree? What about when I apply the model to new data?

The idea is that I would like to use the nodes as a way to cluster my data. In other packages (e.g. SPSS), I can save the predicted class, probabilities, and node number for further analysis.

Given how powerful R can be, I imagine there is a simple solution to this.

like image 327
Btibert3 Avatar asked May 08 '26 18:05

Btibert3


1 Answers

Try using the partykit package:

library(rpart)
z.auto <- rpart(Mileage ~ Weight, car.test.frame)
library(partykit)
z.auto2 <- as.party(z.auto)
predict(z.auto2, car.test.frame[1:3,], type = "node")

# Eagle Summit 4 Ford Escort   4  Ford Festiva 4 
#              7               7               7 
like image 75
topepo Avatar answered May 10 '26 09:05

topepo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!