Rpart node assignment

Is it possible to retrieve the node assignment for an installed tree rpart

? How about when I apply the model to new data?

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

Given how powerful R can be, I suppose there is a simple solution.

+3


source to share


1 answer


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 

      

+11


source







All Articles