split.data = function(data, p = 0.7, s = 666){
set.seed(s)
index = sample(1:dim(data)[1])
train = data[index[1:floor(dim(data)[1] * p)], ]
test = data[index[((ceiling(dim(data)[1] * p)) + 1):dim(data)[1]], ]
return(list(train = train, test = test))
}
allset= split.data(train.data, p = 0.7)
trainset = allset$train
testset = allset$test
train.ctree = ctree(Survived ~ Pclass + Sex + Age + SibSp + Fare
+ Parch + Embarked, data=trainset)
ctree.predict = predict(train.ctree, testset)
confusionMatrix(ctree.predict, testset$Survived)
It is a code to predict passenger survival from Titanic dataset. In the training set, the number of levels is not matching with the test test. The probabilities are not rounded off and exist as separate levels.