I have an output for my printcp but I don't know how to call certain variables from it. For example:
data(iris)
library(caret)
idx <- createDataPartition(iris$Species,list=FALSE, p = .67,times = 1)
IrisTrain <- iris[ idx,]
IrisTest <- iris[-idx,]
iris_model <- rpart(Species ~ ., data = IrisTrain)
err_mat<-printcp(iris_model)
err_mat
gives me an output that looks like this:
Now I know that I can calculate resubstitution error by computing: (.66667*.044118)*100 = 2.94% But is there a way that I don't have to do this manually?
Also I can call upon 0.044118 by:
colnames(err_mat)
which outputs certain variables: "CP" "nsplit" "rel error" "xerror" "xstd" and I can extract 0.044118 by:
lenn=length(err_mat[,'rel error'])
err_mat[lenn,'rel error']
But how do I grab the Root Node Error????
I am trying to run this multiple times and I need to be able to call whatever the rootnodeerror is. Then I can just compute with the variables.
Otherwise if this is not possible what is the code to compute re substitution error? I feel like I have looked everywhere and it's all manual from results and not actual automated code as I want to loop multiple times and need to call variables.
Thank you.