Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 53 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. library(rpart);
  2.  
  3. library(rpart.plot)
  4.  
  5. data(ptitanic);
  6.  
  7. attr(ptitanic$age,"class") <- NULL;
  8.  
  9. class(ptitanic$age);
  10.  
  11. #This is a function which draws the tree
  12.  
  13. arbre=function(data){
  14.  
  15.   set.seed(415)
  16.  
  17.    ptitanicTree  = rpart(survived~., data = data,
  18.                         control = rpart.control(minsplit = 5, cp = 0),
  19.                         method = "class")      
  20.  
  21.  
  22.    ptitanicOptimal = prune(ptitanicTree,
  23.                            cp = ptitanicTree$cptable[which.min(ptitanicTree$cptable[,4]),1] )
  24.  
  25.  
  26.    prp(ptitanicOptimal,extra=1)
  27. }
  28.  
  29. data1=ptitanic[,c(1,2,3,4,5,6)];
  30.  
  31. arbre(data1)
  32.  
  33. # I change the position switching column 5 and 6
  34. data2=ptitanic[,c(1,2,3,4,6,5)];
  35.  
  36. # Here i get an another tree : why ?
  37. arbre(data2)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top