Yashwanth M.R
2012-Feb-09 11:25 UTC
[R] To write a function for getting the node numbers in "rpart" analysis..
## To read .csv file(data) and performing "rpart" ## # library(Hmisc) library(rpart) read.csv("D:/Training/RRE/Revolution(My Projects)/Project1/RProject(pmml from SPSS)/telco_churn.csv", header = TRUE, sep = ",", quote="\"", dec=".") # help(read.csv) Telco<- read.table(file = "D:/Training/RRE/Revolution(My Projects)/Project1/RProject(pmml from SPSS)/telco_churn.csv", header = TRUE, sep = ",") names(Telco) ################################## ################################## ## To make factor variable ## Telco$region<-factor(Telco$region,levels=c(1,2,3,4,5),labels=c("Zone1","Zone2","Zone3","Zone4","Zone5")) Telco$ed<-factor(Telco$ed,levels=c(1,2,3,4,5),labels=c("DidNotHighSchool","HighSchoolDegree","SomeCollege", "CollegeDegree","PostUndergraduateDegree")) Telco$marital<-factor(Telco$marital,,levels=c(0,1),labels=c("Married","Un-married")) Telco$churn<-factor(Telco$churn,levels=c(0,1),labels=c("NO","YES")) ################################## ################################## ## To perform "rpart" ## Telco.rpart <- rpart(churn ~ region+ed+marital+tenure+age+address+income,data=Telco,method="class") plot(Telco.rpart,compress=FALSE,uniform=TRUE) text(Telco.rpart,use.n = TRUE, cex = .75) ################################## ################################## ## To predict "rpart" ## TelcoPredicted <- predict(Telco.rpart,type="class") # Prediction/Scoring ################################## ################################## In the above computation, I would prefer to get the list of "node numbers" parallely for the each of the predictions of "TelcoPredicted". Please help me writing a function for this. -- View this message in context: http://r.789695.n4.nabble.com/To-write-a-function-for-getting-the-node-numbers-in-rpart-analysis-tp4372508p4372508.html Sent from the R help mailing list archive at Nabble.com.