## Decision tree example ## Install all necessary packages and libraries
install.packages('caTools") library(caTools)
install.packages("party") library(party)
install.packages("dplyr") library(dplyr)
## Read input dataset "readingSkills data("readingSkills") dim(readingSkills)
## Split dataset into Train and Test data sample data<-sample.split(readingSkills, SplitRatio=0.8) train_data<-subset(readingSkills, sample_data==TRUE) test_data<-subset(readingSkills, sample_data==FALSE)
## Create decision tree model using ctree function
model<-ctree(nativeSpeaker, train_data)
## testing the model, finding out people who are native speakers ## and those who are not predict_model<-Predict(model,test_data)
m_table<-table(test data$nativeSpeaker, predict_model)
## Checking the accuracy of the model ac_test<-sum(diag(m_table))/sum(m_table) ac_test
print(paste(Accuracy for the test of the model is,ac test))