0

I usually do decissions trees in SPSS to get targets from a DDBB, I did a bit of research and found that there are three packages: tree, party and rpart that are available for R, but which is better for that task?

Thanks!

JJ1603
  • 586
  • 1
  • 7
  • 16
  • I've used party in past and it's quite nice. Here is link to example of use in one of my projects: https://github.com/fiedukow/SejMOWaKlasyfikacja/blob/master/prediction_models.r – Yester Jul 28 '15 at 11:33
  • 2
    I have flagged this question to be closed. I think that it is primarily opinion based because *which is better* can depend on several factors, even personal tastes about programming styles. – SabDeM Jul 28 '15 at 12:04

1 Answers1

2

I have used rpart before, which is handy. I have used for predictive modeling by splitting training and test set. Here is the code. Hope this will give you some idea...

 library(rpart)
    library(rattle)
    library(rpart.plot)
    ### Build the training/validate/test...

data(iris)
nobs <- nrow(iris) 
train <- sample(nrow(iris), 0.7*nobs)
test <- setdiff(seq_len(nrow(iris)), train)
colnames(iris)


### The following variable selections have been noted.
input <- c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width")
numeric <- c("Sepal.Length","Sepal.Width","Petal.Length","Petal.Width")
categoric <- NULL
target  <-"Species"
risk    <- NULL
ident   <- NULL
ignore  <- NULL
weights <- NULL

#set.seed(500)
# Build the Decision Tree model.
rpart <- rpart(Species~.,
    data=iris[train, ],
    method="class",
    parms=list(split="information"),
      control=rpart.control(minsplit=12,
        usesurrogate=0, 
        maxsurrogate=0))

# Generate a textual view of the Decision Tree model.
print(rpart)
printcp(rpart)

# Decision Tree Plot...
prp(rpart)
dev.new()
fancyRpartPlot(rpart, main="Decision Tree Graph")