I'm new to R, and I'm stuck with a pretty dumb problem.
I will calibrate the regression tree with the rpart package to do some classification and some prediction.
Thanks to R, the calibration part is easy to operate and easy to operate.
#the package rpart is needed library(rpart) # Loading of a big data file used for calibration my_data <- read.csv("my_file.csv", sep=",", header=TRUE) # Regression tree calibration tree <- rpart(Ratio ~ Attribute1 + Attribute2 + Attribute3 + Attribute4 + Attribute5, method="anova", data=my_data, control=rpart.control(minsplit=100, cp=0.0001))
After calibrating the large decision tree, I want the appropriate cluster of some new data (and therefore the predicted value) to be found for the given data sample.
The predict function seems ideal for need.
# read validation data validationData <-read.csv("my_sample.csv", sep=",", header=TRUE)
However, using the predict method predict I just get the predicted ratio of my new elements, and I cannot find a way to get the leaf of the decision tree tree where my new elements belong.
I think this should be pretty easy to get, since the method must find this sheet to return the coefficient.
There are several parameters that can be provided to the prediction method using the class= argument, but for the regression tree, everyone seems to return the same thing (the value of the target attribute of the decision tree)
Does anyone know how to get the corresponding node in the decision tree?
By path.rpart node using the path.rpart method, this will help me understand the results.
r regression cart-analysis decision-tree rpart
antoine
source share