Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(rpart);
- library(rpart.plot)
- data(ptitanic);
- attr(ptitanic$age,"class") <- NULL;
- class(ptitanic$age);
- #This is a function which draws the tree
- arbre=function(data){
- set.seed(415)
- ptitanicTree = rpart(survived~., data = data,
- control = rpart.control(minsplit = 5, cp = 0),
- method = "class")
- ptitanicOptimal = prune(ptitanicTree,
- cp = ptitanicTree$cptable[which.min(ptitanicTree$cptable[,4]),1] )
- prp(ptitanicOptimal,extra=1)
- }
- data1=ptitanic[,c(1,2,3,4,5,6)];
- arbre(data1)
- # I change the position switching column 5 and 6
- data2=ptitanic[,c(1,2,3,4,6,5)];
- # Here i get an another tree : why ?
- arbre(data2)
Add Comment
Please, Sign In to add comment