I'm currently working on a problem with R. I want to apply the classification tree over a data set, but the result seems to be wrong since I've already solved the same problem using Weka, and I got different results.
I got a data set contained in a csv file as follow:
age,menopause,tumor.size,inv.nodes,node.caps,deg.malig,breast,breast.quad,irradiat,class
40-49,premeno,15-19,0-2,yes,3,right,left_up,no,recurrence-events
50-59,ge40,15-19,0-2,no,1,right,central,no,no-recurrence-events
50-59,ge40,35-39,0-2,no,2,left,left_low,no,recurrence-events
40-49,premeno,35-39,0-2,yes,3,right,left_low,yes,no-recurrence-events
40-49,premeno,30-34,3-5,yes,2,left,right_up,no,recurrence-events
and this is the script:
#Open r file
cancer = read.csv("cancer.csv")
#Data Exploration
summary(cancer)
str(cancer)
#Divide into test and train sets
set.seed(1234)
ind <- sample(2, nrow(cancer), replace=TRUE, prob=c(0.7, 0.3))
trainData <- cancer[ind==1,]
testData <- cancer[ind==2,]
#Build the model
library(party)
cancermodel <- class ~ age + menopause + tumor.size + inv.nodes + node.caps + deg.malig + breast + breast.quad + irradiat
cancertree <- ctree(cancermodel,trainData)
table(predict(cancertree),trainData$class)
#Draw tree
plot(cancertree, type="simple")
#Testset
testPred <- predict(cancertree, newdata = testData)
table(testPred, testData$class)