library(kableExtra)
  1. you can provide feedback how he can improve his approach to data science.

  2. You may also identify and justify the choice of classifiers Ruffio ran to complete this task.

  3. You can compare the performance metrics of classifiers and provide an explanation for the observed performance variances.

Ruffio’s data

We start by looking at the data Ruffio has to work with.

traindatafile<-'car_eval_train.csv'
trdata<-read.csv(traindatafile,head=T,sep=',')

car_eval<-trdata
names(car_eval)<-c("buying","maint","doors","persons","lug_boot","safety","class")
names(trdata)<-c("buying","maint","doors","persons","lug_boot","safety","class")

trdata %>% kable() %>% kable_styling() %>% scroll_box(width = "800px", height = "400px")
buying maint doors persons lug_boot safety class
high low 5more 2 small med unacc
low med 4 2 big low unacc
vhigh vhigh 5more more small low unacc
med low 3 2 small med unacc
high high 2 2 small low unacc
med vhigh 4 4 big high acc
med med 5more 2 big high unacc
med vhigh 2 2 big high unacc
vhigh med 5more 4 big high acc
low high 5more 4 med high vgood
high med 2 more med high acc
vhigh med 4 2 small high unacc
med med 3 4 small low unacc
high vhigh 2 more small med unacc
high low 4 2 med high unacc
med med 4 4 med low unacc
vhigh low 5more 4 big med acc
vhigh low 3 4 small low unacc
vhigh vhigh 3 more med low unacc
vhigh high 5more 2 big low unacc
low low 3 2 small low unacc
low high 5more 2 big med unacc
vhigh med 4 4 med high acc
vhigh vhigh 2 4 big high unacc
high high 4 more med med acc
vhigh med 3 more med high acc
low high 4 4 big low unacc
med high 2 2 small low unacc
med low 2 more big high vgood
high med 3 more big low unacc
low low 3 4 big high vgood
vhigh med 3 more big med acc
low med 4 4 small low unacc
vhigh vhigh 4 2 big med unacc
vhigh vhigh 5more 2 small high unacc
med med 4 2 small low unacc
med high 2 4 small low unacc
high med 3 2 med med unacc
vhigh low 4 more small med unacc
vhigh low 3 2 med low unacc
high med 5more 2 big high unacc
low med 4 more big low unacc
med low 5more more big high vgood
vhigh high 4 4 small med unacc
high high 4 4 small low unacc
vhigh high 4 4 big high unacc
high low 4 more big low unacc
vhigh vhigh 4 more small low unacc
med low 2 more med low unacc
vhigh med 2 2 med low unacc
high high 5more more big low unacc
med low 2 2 med low unacc
vhigh high 3 2 small med unacc
low high 2 4 small high acc
high low 2 more big low unacc
high high 5more 2 big med unacc
vhigh low 5more 2 med high unacc
med vhigh 5more 4 med high acc
vhigh low 3 4 med high acc
med med 2 2 small med unacc
low med 5more 2 big med unacc
med vhigh 4 4 small low unacc
med med 3 more small med acc
med vhigh 3 4 small low unacc
high med 5more more big low unacc
high med 2 2 big low unacc
low med 4 more small low unacc
med med 2 more big low unacc
vhigh high 5more 4 big low unacc
med high 3 2 med high unacc
high low 3 more small med unacc
med high 2 4 big low unacc
low high 2 more med high acc
low high 5more 4 big low unacc
low med 3 2 big med unacc
vhigh vhigh 5more 4 big high unacc
low vhigh 3 more small low unacc
vhigh high 3 2 med med unacc
med high 4 2 small high unacc
high high 2 2 med med unacc
low med 5more 2 med high unacc
low med 2 2 small low unacc
high high 2 more small low unacc
med med 4 more small high acc
vhigh med 4 more big high acc
vhigh med 3 4 small high acc
med med 5more 2 small high unacc
vhigh low 4 4 big high acc
vhigh low 2 more small med unacc
vhigh low 3 4 big low unacc
med med 4 4 big low unacc
med high 4 2 small med unacc
med high 5more 4 med low unacc
high high 5more 2 small low unacc
high med 2 4 small high acc
vhigh vhigh 3 4 big high unacc
high vhigh 4 more small low unacc
vhigh high 3 4 big med unacc
high low 5more 2 small low unacc
vhigh med 3 4 small med unacc
med high 3 2 med low unacc
med high 2 more big med acc
med high 5more 4 med med acc
med vhigh 2 2 med high unacc
low low 4 more big low unacc
vhigh med 2 more med low unacc
med vhigh 5more more small med unacc
low high 3 more med low unacc
vhigh high 4 4 small high unacc
high low 2 4 big med acc
vhigh vhigh 3 2 small high unacc
high low 3 2 med high unacc
high vhigh 4 2 big med unacc
high high 5more more small high acc
low low 5more 4 med low unacc
low med 5more 4 small med acc
low low 2 2 big high unacc
med vhigh 5more 2 small med unacc
low vhigh 4 more med low unacc
high high 4 more small high acc
high med 4 more small med unacc
vhigh high 4 2 small low unacc
high low 4 4 small med unacc
vhigh high 5more more small high unacc
high low 2 2 big med unacc
low med 3 more med med good
med med 3 more big med acc
high high 2 2 big low unacc
med low 4 4 small med acc
vhigh vhigh 5more 2 small med unacc
vhigh high 4 more med med unacc
vhigh low 3 2 small low unacc
vhigh high 3 more small med unacc
high vhigh 3 2 med high unacc
med vhigh 3 more big med acc
high high 2 4 med high acc
vhigh med 2 more small med unacc
med med 2 4 small med acc
med med 4 more small med acc
vhigh vhigh 5more 4 med high unacc
low vhigh 2 4 small med unacc
high vhigh 2 4 small low unacc
med med 4 4 big med acc
low med 5more 2 big low unacc
med vhigh 5more 4 med low unacc
med low 4 2 med high unacc
low low 5more 2 small high unacc
low vhigh 5more 4 big low unacc
med vhigh 3 more small high acc
low med 3 4 med high good
low high 5more more med med acc
low med 4 2 med med unacc
med vhigh 2 2 big med unacc
low vhigh 5more more med med acc
vhigh high 4 2 small med unacc
low med 2 4 small med acc
med vhigh 2 4 med high acc
low low 2 4 med med acc
med low 2 more med high good
vhigh low 5more 4 med med acc
high med 5more 2 med high unacc
med low 3 2 big high unacc
low low 4 4 big low unacc
vhigh vhigh 2 2 big med unacc
vhigh high 5more 4 big high unacc
low high 5more 2 med med unacc
vhigh vhigh 3 4 small low unacc
med low 5more 4 big med good
med low 3 2 small low unacc
high high 5more more med low unacc
low vhigh 4 2 small low unacc
low vhigh 2 more big low unacc
low low 5more 2 small low unacc
med high 5more 2 big low unacc
med med 3 2 med low unacc
low vhigh 5more more med low unacc
low low 5more 2 big low unacc
high vhigh 2 2 small high unacc
vhigh low 3 more med high acc
high low 2 more med low unacc
low vhigh 5more 2 med high unacc
high high 4 2 small med unacc
low high 4 more big low unacc
low med 2 2 med med unacc
high low 5more more med med acc
vhigh vhigh 2 more big low unacc
med med 2 2 med high unacc
high vhigh 3 4 big low unacc
vhigh low 5more 2 small low unacc
med high 3 4 small med unacc
low low 3 2 small med unacc
vhigh low 4 more med med acc
high high 3 4 big high acc
med low 4 4 small high good
low high 5more 4 big high vgood
low low 5more 4 small high good
high med 4 4 big high acc
high low 4 more med med acc
low med 2 4 small high good
vhigh high 2 2 small low unacc
vhigh med 5more 2 med low unacc
low med 4 2 med high unacc
high low 2 more small low unacc
high low 4 2 small low unacc
vhigh vhigh 2 4 med med unacc
med vhigh 3 4 med low unacc
low med 4 2 small low unacc
high vhigh 2 2 med high unacc
low vhigh 5more 4 big high acc
vhigh vhigh 2 4 big med unacc
med low 3 2 big low unacc
med high 3 4 med low unacc
med vhigh 3 2 med low unacc
high med 4 more med med acc
high med 5more 4 big high acc
med low 5more 2 med high unacc
high high 4 4 small high acc
low vhigh 4 more med med acc
med med 2 more small low unacc
low vhigh 5more 2 big high unacc
med low 5more 2 med med unacc
low vhigh 4 4 big low unacc
vhigh high 5more more med high unacc
med low 3 more small med acc
high low 4 more small low unacc
vhigh high 5more more small med unacc
med low 5more more big med good
low med 3 4 small med acc
low high 4 4 big med acc
high high 3 4 big med acc
med vhigh 4 more med low unacc
high high 2 more med low unacc
vhigh med 5more 4 med low unacc
high med 3 2 big med unacc
low high 3 2 med med unacc
med high 5more 4 small high acc
low med 3 4 med low unacc
med low 5more more small med acc
vhigh med 5more 4 small med unacc
med low 5more more med low unacc
high vhigh 3 4 big med unacc
low high 3 more big high vgood
vhigh low 4 2 big med unacc
vhigh high 3 2 med high unacc
high low 2 2 small high unacc
vhigh low 2 4 big med acc
med low 5more 2 small high unacc
vhigh high 4 2 med low unacc
med med 3 more big low unacc
vhigh high 4 more small med unacc
high vhigh 3 more big med unacc
vhigh med 5more more med high acc
vhigh med 5more 2 small low unacc
vhigh vhigh 3 4 med med unacc
med vhigh 2 more small high unacc
med high 4 more big med acc
med high 2 4 small med unacc
low high 4 2 big med unacc
high med 3 4 small med unacc
med low 5more more small low unacc
low low 2 2 big low unacc
low med 5more 4 med med good
med high 4 more small med unacc
med med 3 4 small med acc
low high 2 2 small low unacc
med med 2 4 big high vgood
med high 3 more big low unacc
low med 3 2 big high unacc
high low 5more 4 big low unacc
high vhigh 5more 4 med high unacc
med vhigh 5more more med high acc
low low 3 2 big high unacc
med low 3 4 big high vgood
vhigh high 2 4 small low unacc
low high 2 more small low unacc
low med 2 more big high vgood
vhigh low 5more 4 med high acc
high high 5more more big high acc
low low 2 more big high vgood
high vhigh 5more 2 big low unacc
med high 3 more med high acc
vhigh med 4 2 small low unacc
vhigh vhigh 4 2 small med unacc
low high 5more more big med acc
low low 5more 2 small med unacc
med med 2 4 big low unacc
low vhigh 3 4 big med acc
high high 3 more med high acc
high high 2 2 small med unacc
vhigh vhigh 3 4 big med unacc
low vhigh 2 4 med high acc
vhigh vhigh 5more more big low unacc
low low 5more 4 big low unacc
high vhigh 5more more small high unacc
low low 4 2 big high unacc
vhigh med 2 4 small high acc
high med 2 more big high acc
med high 5more 2 med low unacc
vhigh low 2 4 small low unacc
med high 4 2 med low unacc
med high 5more more small med unacc
low vhigh 3 4 small low unacc
med high 3 2 big low unacc
med vhigh 2 4 small low unacc
vhigh med 5more 4 small low unacc
med low 4 4 med high vgood
med low 4 more med med good
med high 4 4 small med unacc
vhigh vhigh 4 more med med unacc
high low 3 2 med low unacc
high high 3 2 med med unacc
low low 3 4 big med good
med med 2 2 big high unacc
low low 3 2 med low unacc
med vhigh 4 more small med unacc
med vhigh 3 4 small med unacc
med low 5more 4 med med good
high high 2 4 small high acc
med low 2 2 big med unacc
low vhigh 4 2 big med unacc
vhigh low 2 2 med med unacc
high vhigh 3 2 small high unacc
low high 4 2 med med unacc
low vhigh 4 4 big high acc
vhigh med 4 2 big high unacc
vhigh low 2 4 med med unacc
high low 2 4 big low unacc
high low 4 4 med low unacc
vhigh med 5more more med med acc
med vhigh 5more 4 big med acc
low high 2 2 small med unacc
high low 2 2 big low unacc
low med 5more 4 big med good
low high 2 more small med unacc
high vhigh 2 2 big med unacc
high low 3 2 small med unacc
vhigh high 3 4 big low unacc
high vhigh 5more 4 med low unacc
vhigh med 3 2 small high unacc
high high 3 2 small med unacc
high med 4 more small low unacc
med high 3 more med low unacc
med med 4 4 small low unacc
low low 2 more small high unacc
med high 2 2 big med unacc
high high 5more 4 small med unacc
vhigh high 4 4 big med unacc
med low 5more 4 med high vgood
vhigh vhigh 3 more small low unacc
high vhigh 4 more small med unacc
low vhigh 4 2 small high unacc
low high 2 4 big med acc
med med 5more 4 small high acc
high high 4 more small med unacc
vhigh low 2 more med med unacc
vhigh med 4 2 med med unacc
vhigh med 3 2 med high unacc
med vhigh 4 more small low unacc
high med 4 more big med acc
low high 4 more med low unacc
vhigh low 3 2 small med unacc
med high 2 2 big high unacc
high high 5more 4 small high acc
vhigh vhigh 5more more med high unacc
vhigh high 2 4 big low unacc
med vhigh 4 4 med high acc
low med 5more more med high vgood
low med 3 2 small low unacc
med high 5more 2 med high unacc
high med 3 more small med unacc
high vhigh 3 more big low unacc
med low 4 2 small high unacc
high high 5more 4 big med acc
vhigh high 3 4 small med unacc
vhigh low 3 4 big med acc
med vhigh 2 4 big low unacc
low med 5more 2 med low unacc
high med 5more 2 med low unacc
high low 3 2 med med unacc
low med 2 4 big high vgood
high high 4 2 small low unacc
med med 5more more big med acc
med vhigh 5more more med med acc
vhigh vhigh 3 more big high unacc
vhigh low 4 more small low unacc
low vhigh 4 more big low unacc
med med 4 2 big low unacc
high low 5more 2 big low unacc
med low 5more 4 med low unacc
med vhigh 5more more small high acc
low low 5more more small low unacc
vhigh low 5more 2 small med unacc
high low 4 4 med med acc
vhigh low 2 more big high acc
high vhigh 4 4 small low unacc
high vhigh 3 4 big high unacc
high med 4 4 med med acc
high vhigh 2 4 small high unacc
low vhigh 4 2 med high unacc
med med 5more more small med acc
vhigh high 3 4 med low unacc
vhigh vhigh 2 more small low unacc
high low 5more 4 med high acc
low med 5more more big low unacc
vhigh vhigh 4 2 big high unacc
med high 3 2 med med unacc
low vhigh 2 more med low unacc
med high 2 4 small high acc
vhigh high 2 more small med unacc
vhigh high 3 more big med unacc
vhigh med 2 more med high acc
med med 2 2 big med unacc
low vhigh 5more 4 small low unacc
vhigh high 3 more small low unacc
med med 5more more med low unacc
low vhigh 2 2 med med unacc
vhigh low 4 4 small low unacc
vhigh med 2 4 small low unacc
low low 3 more med low unacc
vhigh low 3 more med med acc
med med 5more 4 med low unacc
vhigh med 5more more small med unacc
med low 3 2 med high unacc
vhigh low 3 more big low unacc
low med 4 2 med low unacc
high vhigh 3 more med high unacc
vhigh med 4 4 med med acc
vhigh vhigh 4 more big high unacc
low vhigh 3 2 small med unacc
vhigh med 5more more big low unacc
low low 4 4 small med acc
high high 3 4 small high acc
low vhigh 3 2 small low unacc
low high 3 2 big high unacc
high low 4 4 small low unacc
vhigh med 4 2 big low unacc
vhigh vhigh 2 2 small high unacc
high med 3 more small high acc
vhigh vhigh 4 more med high unacc
med med 5more 2 small low unacc
med low 5more more big low unacc
med high 3 4 small high acc
low vhigh 2 4 med med unacc
vhigh high 3 more small high unacc
high low 2 4 med low unacc
high low 4 more small med unacc
med med 5more 4 med high vgood
low med 4 2 small high unacc
high med 3 4 small high acc
low med 3 more small low unacc
med vhigh 3 2 small med unacc
low high 5more 2 med high unacc
vhigh low 2 4 big low unacc
high low 5more more small low unacc
low med 2 4 big low unacc
high low 2 2 small low unacc
vhigh high 2 4 med med unacc
low low 5more more med med good
med vhigh 2 4 small med unacc
med med 3 4 med med acc
med high 2 2 med low unacc
vhigh vhigh 2 more big high unacc
low high 2 2 med low unacc
low high 4 4 med high vgood
high med 5more more med high acc
vhigh high 5more 4 med med unacc
low high 4 more med high vgood
low vhigh 2 2 big med unacc
med low 2 2 small med unacc
med vhigh 5more 4 small low unacc
low low 4 4 big high vgood
low high 4 2 small low unacc
vhigh vhigh 3 2 big high unacc
high vhigh 3 2 small low unacc
low high 4 4 small high acc
low vhigh 2 2 med low unacc
vhigh high 2 more med med unacc
low high 5more 4 small med acc
low high 2 2 big low unacc
high vhigh 4 more med high unacc
med vhigh 2 more big med acc
low vhigh 2 4 big med acc
med vhigh 2 more small low unacc
vhigh high 2 more big high unacc
high high 2 more med med unacc
vhigh med 3 2 big med unacc
med med 2 more big med acc
high high 3 4 med high acc
low low 5more 4 small low unacc
high low 4 more med high acc
vhigh low 3 more big med acc
high low 5more 4 small low unacc
high med 3 more big med acc
high low 3 more med med acc
vhigh med 3 more small low unacc
high vhigh 3 4 small high unacc
low vhigh 2 more med high acc
med vhigh 5more 4 small high acc
high high 5more 2 small med unacc
high vhigh 5more more small low unacc
med vhigh 5more more small low unacc
med vhigh 5more 4 big low unacc
low vhigh 5more more small med unacc
low low 4 more big med good
low low 3 4 small high good
high vhigh 3 more small low unacc
vhigh vhigh 5more 4 small high unacc
high vhigh 2 4 big low unacc
vhigh low 5more more small med unacc
low vhigh 3 more med low unacc
med high 4 4 med med acc
med low 4 more big high vgood
med high 5more 4 big med acc
vhigh vhigh 3 more small high unacc
vhigh vhigh 2 more big med unacc
low vhigh 4 more small high acc
vhigh high 4 2 big med unacc
med low 3 more med low unacc
med low 4 2 med med unacc
low low 5more 4 med high vgood
med med 3 more big high vgood
high high 2 more med high acc
high low 4 2 med low unacc
low vhigh 3 more big med acc
high high 4 4 big low unacc
vhigh vhigh 2 more small high unacc
low vhigh 2 2 small high unacc
high med 4 2 small high unacc
low med 2 2 med high unacc
vhigh high 4 more med low unacc
low vhigh 3 4 big high acc
vhigh vhigh 3 2 med low unacc
low vhigh 4 more big med acc
low vhigh 5more 2 med low unacc
med med 4 2 small med unacc
vhigh med 3 4 med med unacc
med med 5more 2 big med unacc
med med 4 more big high vgood
high high 3 more small low unacc
vhigh low 4 4 small high acc
med low 4 more med low unacc
low vhigh 4 2 med low unacc
med med 5more 4 small med acc
vhigh vhigh 2 2 big low unacc
high high 4 more big med acc
low med 3 more big low unacc
low high 3 4 med low unacc
vhigh low 3 2 big med unacc
high med 5more 4 small high acc
low vhigh 5more more big med acc
high high 4 4 med med acc
vhigh vhigh 2 more med low unacc
high low 4 more big high acc
low high 4 more small low unacc
low med 4 2 small med unacc
high med 2 2 small high unacc
high vhigh 5more more big high unacc
high low 3 2 big med unacc
high med 4 2 med low unacc
vhigh high 4 more small high unacc
med vhigh 4 2 small high unacc
vhigh high 2 2 big med unacc
low med 5more 4 med low unacc
med med 4 2 med high unacc
high vhigh 3 2 big high unacc
med vhigh 4 4 med med acc
vhigh vhigh 3 4 small high unacc
high vhigh 2 more med low unacc
low med 5more more big med good
vhigh low 2 4 med high acc
low high 2 more big low unacc
high vhigh 5more more med low unacc
vhigh high 3 2 med low unacc
low vhigh 4 more small low unacc
med med 5more more big low unacc
vhigh med 3 2 small med unacc
vhigh med 4 2 med high unacc
vhigh high 4 4 med med unacc
vhigh high 2 2 med med unacc
low low 2 4 med high good
med low 3 4 small med acc
high high 2 4 big low unacc
vhigh low 5more 2 big low unacc
vhigh vhigh 3 more med med unacc
vhigh med 3 more small med unacc
vhigh vhigh 4 more big low unacc
med vhigh 4 more big low unacc
low med 5more 2 small low unacc
med high 4 more med high acc
low low 2 4 small med acc
low vhigh 4 more med high acc
vhigh vhigh 2 2 med low unacc
vhigh vhigh 3 2 small med unacc
med vhigh 3 2 small high unacc
low low 5more more med low unacc
low vhigh 5more more small high acc
high low 3 4 med med unacc
low high 2 4 small low unacc
med vhigh 5more more big low unacc
med med 5more 2 med med unacc
vhigh vhigh 5more 2 big high unacc
low med 3 4 big low unacc
high med 3 2 small high unacc
high med 3 more med med acc
low low 2 2 med med unacc
high med 2 more small med unacc
low vhigh 5more 4 med med acc
med high 3 4 big high acc
low vhigh 4 2 big high unacc
vhigh vhigh 3 more big low unacc
high med 3 2 med low unacc
high med 3 4 med med unacc
vhigh vhigh 2 2 small med unacc
low low 4 4 big med good
high vhigh 5more 2 small high unacc
vhigh low 4 4 med high acc
low vhigh 3 more big high acc
high med 2 2 big med unacc
low vhigh 4 2 med med unacc
vhigh low 5more more med high acc
med low 3 4 med low unacc
med vhigh 5more more big med acc
high vhigh 5more more small med unacc
med high 4 more small high acc
low med 5more more big high vgood
med low 4 2 big high unacc
med low 4 2 small med unacc
med high 5more 4 small med unacc
vhigh low 5more 2 big high unacc
high high 5more more med high acc
low med 4 4 big high vgood
vhigh med 4 more small high acc
high vhigh 4 4 med high unacc
vhigh low 5more more small high acc
high high 4 2 med low unacc
low med 4 more big high vgood
vhigh vhigh 3 4 big low unacc
high low 2 more big high acc
med low 2 more big med good
high med 4 4 big med acc
low med 4 4 med low unacc
high med 2 4 med med unacc
low high 5more 4 big med acc
high med 2 4 big low unacc
high med 5more 2 big low unacc
vhigh vhigh 4 4 small med unacc
vhigh med 4 2 small med unacc
med low 2 4 med low unacc
low high 4 4 med med acc
vhigh vhigh 2 more small med unacc
low high 2 2 med high unacc
vhigh high 4 more big med unacc
low high 2 2 med med unacc
vhigh vhigh 5more more big med unacc
med vhigh 5more more med low unacc
med vhigh 3 2 small low unacc
med vhigh 2 4 big high acc
med vhigh 5more 2 med high unacc
low low 5more more med high vgood
high low 3 more med high acc
vhigh high 5more more big high unacc
med low 5more 2 big low unacc
high high 3 more med med acc
vhigh low 4 4 small med unacc
high high 5more 4 med med acc
low high 4 2 big high unacc
high low 5more more small high acc
low low 4 2 small high unacc
vhigh high 5more more big med unacc
low vhigh 2 more big med acc
med high 2 4 big med acc
high low 3 2 big low unacc
low high 3 2 small high unacc
high med 3 2 small med unacc
med vhigh 4 2 small low unacc
high vhigh 5more 2 big high unacc
high high 3 2 big high unacc
vhigh vhigh 5more more big high unacc
med high 4 4 big low unacc
vhigh vhigh 2 2 med high unacc
med vhigh 4 2 med high unacc
vhigh vhigh 4 2 small high unacc
med med 2 more small high unacc
med vhigh 3 2 med high unacc
vhigh med 4 more med low unacc
med low 2 4 big low unacc
vhigh high 3 2 big low unacc
high med 5more 4 small low unacc
med low 4 2 small low unacc
med med 4 4 big high vgood
low low 4 2 med low unacc
med med 2 2 med med unacc
high low 5more more big med acc
low high 2 more big high vgood
low vhigh 3 2 big med unacc
med high 5more 2 small low unacc
low high 4 2 small high unacc
vhigh low 3 4 med med unacc
low vhigh 4 more big high acc
high med 4 more med low unacc
low low 4 more small low unacc
vhigh low 4 more big low unacc
vhigh low 2 2 small low unacc
vhigh high 2 4 small high unacc
med low 5more 4 small med acc
vhigh med 2 more small high unacc
vhigh med 3 2 med med unacc
low med 3 4 big high vgood
low med 4 2 big high unacc
high vhigh 5more 4 med med unacc
high vhigh 4 more small high unacc
high vhigh 3 more small med unacc
vhigh high 2 4 med high unacc
med low 4 4 small low unacc
vhigh high 2 4 big med unacc
high high 2 2 med high unacc
vhigh high 3 2 small low unacc
low vhigh 5more 2 big med unacc
vhigh vhigh 4 4 med high unacc
vhigh med 5more more big med acc
low low 3 4 med med acc
high high 4 2 big med unacc
high low 2 4 med high acc
low med 4 4 small high good
high vhigh 2 4 big high unacc
high low 2 more med med unacc
vhigh med 3 4 big low unacc
vhigh med 5more 2 small high unacc
vhigh vhigh 4 4 med low unacc
low low 2 more med low unacc
vhigh high 5more more med low unacc
low med 4 more med high vgood
med high 2 more small med unacc
high low 4 2 big med unacc
vhigh med 5more 2 small med unacc
med med 4 4 small high acc
high vhigh 3 2 med low unacc
vhigh med 2 4 med med unacc
vhigh low 4 2 med low unacc
high low 2 4 small low unacc
high high 2 2 big high unacc
med high 3 2 small med unacc
vhigh low 2 2 small med unacc
low med 3 2 med low unacc
high vhigh 3 more big high unacc
low high 3 more small low unacc
low high 3 more big med acc
vhigh vhigh 5more 2 big low unacc
high high 3 4 big low unacc
med low 2 2 big high unacc
low vhigh 3 more med high acc
high med 3 4 med low unacc
low low 2 2 med low unacc
med low 4 4 big med good
low high 3 more med high vgood
vhigh high 5more more big low unacc
vhigh high 2 2 small high unacc
high high 4 2 med med unacc
med med 3 4 med low unacc
vhigh low 4 4 big low unacc
vhigh vhigh 5more more small high unacc
low low 2 2 small high unacc
vhigh low 2 more big low unacc
high low 2 more big med acc
high med 5more 2 med med unacc
med vhigh 4 2 big high unacc
low vhigh 4 2 small med unacc
med vhigh 2 4 big med acc
vhigh low 5more more big med acc
high low 2 4 small med unacc
vhigh high 4 2 small high unacc
low high 2 4 big high vgood
low vhigh 5more 2 small med unacc
med low 4 4 med low unacc
med high 4 2 big low unacc
med low 3 2 med low unacc
low vhigh 3 4 med med unacc
med med 2 2 big low unacc
low vhigh 3 more small med unacc
low high 5more 4 small low unacc
vhigh low 3 2 big high unacc
low vhigh 3 4 small high acc
low low 5more 4 small med acc
high high 5more more med med acc
low med 2 more small med unacc
low low 2 4 small low unacc
low high 5more 2 big high unacc
med med 3 4 big low unacc
vhigh high 2 2 big high unacc
med vhigh 3 more big high acc
low med 2 2 big high unacc
vhigh med 4 more small med unacc
high med 4 4 med low unacc
low vhigh 2 2 small med unacc
high low 4 more big med acc
high high 5more 2 small high unacc
vhigh vhigh 4 2 big low unacc
med high 4 2 med high unacc
med med 3 more small high acc
med vhigh 4 2 small med unacc
high low 2 more med high acc
high vhigh 5more 2 big med unacc
low low 3 more big low unacc
med vhigh 2 more big high acc
med high 2 2 small med unacc
med low 4 more med high vgood
high low 5more 4 small high acc
vhigh med 3 more big low unacc
vhigh med 2 2 big low unacc
vhigh vhigh 3 4 small med unacc
high med 3 2 med high unacc
high low 4 more med low unacc
med low 3 2 small high unacc
med high 5more 2 small high unacc
med low 4 2 med low unacc
low med 4 more small high good
low vhigh 2 more small low unacc
low low 5more 2 med med unacc
vhigh high 5more 4 small high unacc
vhigh high 5more more med med unacc
vhigh vhigh 4 2 med med unacc
med high 2 4 med med unacc
vhigh high 4 more small low unacc
high vhigh 3 more med low unacc
high med 2 4 big med acc
med vhigh 2 more big low unacc
low vhigh 5more more big high acc
high low 2 2 med high unacc
vhigh med 3 2 med low unacc
high low 4 more small high acc
low vhigh 5more more big low unacc
high low 3 2 big high unacc
vhigh high 5more 4 small med unacc
vhigh med 2 more big low unacc
low med 4 4 big low unacc
vhigh high 3 4 small high unacc
low vhigh 2 2 big low unacc
med med 5more 4 small low unacc
vhigh low 4 4 med low unacc
vhigh vhigh 2 2 small low unacc
vhigh high 3 more big high unacc
vhigh low 3 more small med unacc
high med 5more 4 med high acc
vhigh low 5more more big low unacc
med high 3 more big high acc
vhigh med 3 2 small low unacc
high low 4 2 med med unacc
med low 3 more med high vgood
med med 5more 2 med high unacc
low low 4 4 med high vgood
vhigh vhigh 2 4 small med unacc
med vhigh 3 more big low unacc
vhigh med 2 4 big low unacc
low low 5more 2 med high unacc
med low 2 2 med high unacc
med low 4 4 big low unacc
low high 5more more small low unacc
high low 3 4 small high acc
low high 5more 2 big low unacc
med high 2 2 big low unacc
low vhigh 2 more small high unacc
high med 3 2 small low unacc
vhigh high 2 2 med high unacc
vhigh vhigh 4 4 small low unacc
med high 4 2 med med unacc
med vhigh 3 4 big high acc
vhigh low 4 more small high acc
med med 2 more med high acc
high high 5more more small low unacc
vhigh high 3 2 small high unacc
high vhigh 4 2 med low unacc
low high 3 more small high acc
low low 2 more small med unacc
med low 5more 4 big high vgood
high med 4 2 med high unacc
vhigh med 4 2 med low unacc
low vhigh 5more 2 small high unacc
med low 2 4 med med acc
med vhigh 4 4 big med acc
vhigh high 4 4 med low unacc
vhigh low 4 more med low unacc
vhigh high 3 more med low unacc
low low 5more 4 big high vgood
med med 2 4 med med acc
med low 5more more med high vgood
low high 3 4 med high acc
high high 5more 4 big high acc
high low 5more 4 big high acc
med low 3 2 med med unacc
high low 2 4 small high acc
low med 2 2 big med unacc
vhigh vhigh 5more 4 big low unacc
low low 3 2 big low unacc
vhigh low 3 2 big low unacc
vhigh low 4 2 small low unacc
high high 3 2 small high unacc
med vhigh 3 more med med acc
low vhigh 2 4 big low unacc
high vhigh 2 4 small med unacc
vhigh high 5more 4 med low unacc
low med 2 4 med low unacc
low high 5more more med low unacc
vhigh low 2 2 med high unacc
med med 2 4 big med acc
high vhigh 3 4 med med unacc
low med 2 2 small med unacc
low high 3 2 med high unacc
high low 5more 2 small high unacc
med low 2 4 small high good
med high 4 4 med low unacc
low high 4 2 small med unacc
vhigh low 3 4 big high acc
vhigh high 4 2 med high unacc
vhigh med 4 2 big med unacc
low low 3 4 small low unacc
med low 3 more big med good
low low 4 2 med med unacc
vhigh vhigh 5more more med med unacc
vhigh low 2 more small high unacc
high med 2 2 med high unacc
low med 5more more small high good
high vhigh 2 2 big low unacc
low med 3 2 small med unacc
low high 3 2 med low unacc
med high 5more more big high acc
high vhigh 4 4 med low unacc
high high 5more 2 big low unacc
high low 3 4 big med acc
high med 5more 2 small low unacc
med vhigh 5more 2 big med unacc
high high 4 2 small high unacc
low med 2 4 big med good
vhigh med 4 4 big med acc
vhigh low 3 more med low unacc
vhigh low 4 2 big low unacc
med med 4 2 big high unacc
med med 3 more med low unacc
med low 3 4 big low unacc
med med 4 more med high vgood
low med 2 4 med high good
high med 3 4 big med acc
low vhigh 3 2 small high unacc
med med 3 4 small high acc
low low 3 more small low unacc
high vhigh 2 more small low unacc
high med 2 more small low unacc
low low 3 4 med low unacc
high med 4 2 big low unacc
med low 2 more med med acc
low med 5more 4 small high good
vhigh high 5more 2 big high unacc
vhigh med 5more 4 med high acc
vhigh med 4 4 med low unacc
med high 2 2 small high unacc
high high 3 4 small med unacc
high vhigh 4 4 big low unacc
low vhigh 5more 2 big low unacc
vhigh low 4 2 small high unacc
vhigh vhigh 4 more med low unacc
low med 3 more big med good
vhigh med 5more 2 big high unacc
high vhigh 5more 4 big med unacc
med med 3 more med med acc
low low 5more 4 med med good
med high 2 4 big high acc
high high 5more 2 med low unacc
med low 3 more big low unacc
med high 5more 4 med high acc
low vhigh 5more 4 big med acc
low med 5more more med low unacc
med high 3 more small high acc
med high 3 2 big high unacc
low vhigh 4 4 small low unacc
med med 5more 4 big med acc
high low 5more more med high acc
med vhigh 2 more med low unacc
med vhigh 4 more big high acc
vhigh vhigh 2 more med med unacc
med med 3 2 small low unacc
low med 4 more med med good
vhigh low 4 2 med high unacc
low low 2 4 big med good
med high 2 2 med med unacc
high med 2 4 med low unacc
high vhigh 4 2 small high unacc
vhigh low 2 4 med low unacc
med low 2 4 med high good
vhigh vhigh 4 4 big low unacc
med vhigh 4 4 med low unacc
low low 5more more big high vgood
med high 4 2 big med unacc
low vhigh 2 4 small high acc
vhigh high 4 more big low unacc
high high 3 more small high acc
low high 3 4 small high acc
high vhigh 3 4 small low unacc
low med 4 more small med acc
med low 3 4 big med good
vhigh low 5more 2 big med unacc
med med 5more more med med acc
vhigh low 4 more med high acc
low med 5more 4 big high vgood
high vhigh 2 more big low unacc
vhigh med 3 more big high acc
high med 5more more small high acc
vhigh vhigh 2 4 small high unacc
high high 3 more med low unacc
low med 2 more small low unacc
high med 5more 4 med med acc
vhigh low 2 2 med low unacc
vhigh med 2 2 big high unacc
vhigh med 3 4 big high acc
vhigh high 5more 4 med high unacc
low vhigh 2 more small med unacc
low high 4 4 small low unacc
high high 4 4 big high acc
high high 4 4 big med acc
med low 5more 4 small low unacc
low med 3 2 med med unacc
high high 2 more big med acc
high med 5more more med low unacc
low med 3 2 small high unacc
med med 5more more small high acc
med vhigh 4 2 med med unacc
low low 5more more big low unacc
high med 2 more big low unacc
med low 5more more small high good
vhigh med 4 4 big high acc
high high 2 more small high unacc
low high 2 2 big med unacc
low high 5more more small med acc
high vhigh 3 4 small med unacc
med med 2 4 med low unacc
high low 2 2 big high unacc
low low 3 more med high vgood
med med 5more more small low unacc
vhigh high 2 2 small med unacc
high med 2 more small high unacc
high vhigh 3 2 med med unacc
med vhigh 2 2 small low unacc
med med 4 more big low unacc
vhigh high 3 2 big high unacc
med med 2 4 small low unacc
med low 4 more big med good
high med 2 4 big high acc
med high 4 4 big high acc
med low 3 4 small low unacc
vhigh med 5more 2 med med unacc
high med 2 2 med low unacc
low high 3 4 big med acc
med med 3 2 small med unacc
low vhigh 4 4 med low unacc
low med 2 2 big low unacc
med high 4 more med low unacc
high high 4 more small low unacc
high vhigh 2 more med high unacc
med high 4 more big low unacc
low low 3 4 med high good
vhigh med 4 more big med acc
low vhigh 3 more med med acc
high vhigh 3 2 small med unacc
vhigh med 2 more big med acc
vhigh high 5more 4 big med unacc
low low 4 2 big med unacc
low high 3 4 big low unacc
low med 5more 2 med med unacc
high med 4 4 med high acc
vhigh med 5more more small low unacc
high med 3 more big high acc
vhigh vhigh 3 2 med med unacc
high vhigh 4 more med low unacc
med low 3 4 small high good
low vhigh 4 4 small high acc
vhigh high 3 4 med med unacc
high high 2 4 big high acc
high high 2 more small med unacc
med high 5more more med med acc
low low 5more 4 big med good
med low 4 2 big med unacc
high high 4 more med low unacc
vhigh vhigh 5more 2 small low unacc
high low 3 2 small high unacc
med high 3 2 small low unacc
high vhigh 4 4 small high unacc
high high 3 2 med high unacc
low vhigh 2 more med med unacc
high vhigh 4 4 big med unacc
low high 4 more big med acc
vhigh med 5more 4 small high acc
med high 2 more med low unacc
low vhigh 2 2 med high unacc
high high 4 4 small med unacc
vhigh low 2 more med low unacc
high med 4 2 small med unacc
high vhigh 4 4 big high unacc
high med 3 2 big high unacc
vhigh low 3 more big high acc
med high 5more more small low unacc
high high 3 4 med med unacc
high med 5more 4 small med unacc
med med 4 4 med high vgood
high vhigh 3 4 med low unacc
high vhigh 2 2 small med unacc
med low 4 more small low unacc
med med 3 2 med med unacc
med vhigh 4 2 big med unacc
high low 5more 4 med med acc
high med 3 more small low unacc
vhigh vhigh 5more 4 small med unacc
low high 5more 2 med low unacc
low vhigh 5more 2 small low unacc
high med 4 more small high acc
high high 2 2 med low unacc
med med 3 2 small high unacc
high med 2 2 small low unacc
low low 5more more big med good
low high 5more more big low unacc
med vhigh 4 more small high acc
vhigh vhigh 4 4 small high unacc
med low 2 4 big med good
high med 5more 4 big low unacc
low high 5more 2 small high unacc
low high 5more 2 small low unacc
med med 2 more med low unacc
high high 3 4 med low unacc
low low 4 2 med high unacc
vhigh med 2 2 small med unacc
med med 3 4 med high acc
med med 2 4 small high acc
vhigh vhigh 4 more small high unacc
low med 2 more small high unacc
vhigh med 2 more big high acc
high low 2 2 med low unacc
med low 4 more small high good
high med 4 2 big high unacc
high low 3 4 big high acc
high low 2 more small med unacc
low high 2 more med low unacc
high low 3 4 big low unacc
low high 3 4 med med acc
vhigh vhigh 3 more med high unacc
low med 5more more small med acc
vhigh low 5more 4 big high acc
med vhigh 3 4 big low unacc
high vhigh 2 2 med med unacc
low high 3 4 small med acc
high low 3 more big low unacc
med high 3 4 big med acc
med vhigh 5more 4 med med acc
med high 5more 2 big high unacc
high high 4 2 big low unacc
vhigh low 3 4 small med unacc
vhigh med 5more 4 big low unacc
vhigh low 4 2 med med unacc
vhigh med 4 more small low unacc
high vhigh 5more 2 med high unacc
high low 2 4 med med unacc
vhigh vhigh 4 2 small low unacc
high med 3 4 big high acc
med low 5more 2 big high unacc
vhigh low 4 more big med acc
vhigh low 5more 4 big low unacc
high vhigh 2 more small high unacc
vhigh med 4 more med high acc
high med 4 4 small high acc
low vhigh 2 4 med low unacc
high vhigh 2 4 med med unacc
med high 2 more big low unacc
vhigh high 5more 2 small high unacc
high vhigh 4 more big high unacc
high med 2 2 small med unacc
high med 2 4 small med unacc
low med 3 4 big med good
high med 4 2 big med unacc
vhigh vhigh 4 2 med high unacc
high med 3 more med high acc
low low 2 more big low unacc
vhigh vhigh 3 2 small low unacc
med med 4 2 big med unacc
high low 4 2 small med unacc
low low 4 4 small high good
med high 3 2 big med unacc
low med 3 4 med med acc
low low 4 more med low unacc
med vhigh 2 more small med unacc
vhigh med 2 more small low unacc
vhigh high 2 4 big high unacc
high vhigh 5more 2 small low unacc
high vhigh 3 2 big low unacc
vhigh med 4 4 big low unacc
vhigh high 5more 2 med med unacc
low low 5more 2 med low unacc
med high 5more more big med acc
med low 5more more med med good
vhigh high 5more 4 small low unacc
high high 2 4 med med unacc
vhigh low 2 4 small med unacc
med med 4 more small low unacc
high high 3 more big high acc
med vhigh 3 4 med med unacc
vhigh med 3 2 big low unacc
vhigh high 4 4 small low unacc
high low 5more more small med unacc
med vhigh 4 4 small med unacc
med vhigh 4 2 med low unacc
low low 5more 2 big high unacc
med low 2 4 small med acc
vhigh med 3 2 big high unacc
low med 2 2 med low unacc
high med 2 4 med high acc
nrow(trdata)
## [1] 1210
tstdatafile<-'car_eval_test.csv'
tstdata<-read.csv(tstdatafile,head=T,sep=',')
names(tstdata)<-names(car_eval)

tstdata %>% kable() %>% kable_styling() %>% scroll_box(width = "800px", height = "400px")
buying maint doors persons lug_boot safety class
vhigh vhigh 2 2 med med unacc
vhigh vhigh 2 2 big high unacc
vhigh vhigh 2 4 small low unacc
vhigh vhigh 2 4 med low unacc
vhigh vhigh 2 4 med high unacc
vhigh vhigh 2 4 big low unacc
vhigh vhigh 2 more med high unacc
vhigh vhigh 3 2 med high unacc
vhigh vhigh 3 2 big low unacc
vhigh vhigh 3 2 big med unacc
vhigh vhigh 3 4 med low unacc
vhigh vhigh 3 4 med high unacc
vhigh vhigh 3 more small med unacc
vhigh vhigh 3 more big med unacc
vhigh vhigh 4 2 med low unacc
vhigh vhigh 4 4 med med unacc
vhigh vhigh 4 4 big med unacc
vhigh vhigh 4 4 big high unacc
vhigh vhigh 4 more small med unacc
vhigh vhigh 4 more big med unacc
vhigh vhigh 5more 2 med low unacc
vhigh vhigh 5more 2 med med unacc
vhigh vhigh 5more 2 med high unacc
vhigh vhigh 5more 2 big med unacc
vhigh vhigh 5more 4 small low unacc
vhigh vhigh 5more 4 med low unacc
vhigh vhigh 5more 4 med med unacc
vhigh vhigh 5more 4 big med unacc
vhigh vhigh 5more more small med unacc
vhigh vhigh 5more more med low unacc
vhigh high 2 2 med low unacc
vhigh high 2 2 big low unacc
vhigh high 2 4 small med unacc
vhigh high 2 4 med low unacc
vhigh high 2 more small low unacc
vhigh high 2 more small high unacc
vhigh high 2 more med low unacc
vhigh high 2 more med high unacc
vhigh high 2 more big low unacc
vhigh high 2 more big med unacc
vhigh high 3 2 big med unacc
vhigh high 3 4 small low unacc
vhigh high 3 4 med high unacc
vhigh high 3 4 big high unacc
vhigh high 3 more med med unacc
vhigh high 3 more med high unacc
vhigh high 3 more big low unacc
vhigh high 4 2 med med unacc
vhigh high 4 2 big low unacc
vhigh high 4 2 big high unacc
vhigh high 4 4 med high unacc
vhigh high 4 4 big low unacc
vhigh high 4 more med high unacc
vhigh high 4 more big high unacc
vhigh high 5more 2 small low unacc
vhigh high 5more 2 small med unacc
vhigh high 5more 2 med low unacc
vhigh high 5more 2 med high unacc
vhigh high 5more 2 big med unacc
vhigh high 5more more small low unacc
vhigh med 2 2 small low unacc
vhigh med 2 2 small high unacc
vhigh med 2 2 med med unacc
vhigh med 2 2 med high unacc
vhigh med 2 2 big med unacc
vhigh med 2 4 small med unacc
vhigh med 2 4 med low unacc
vhigh med 2 4 med high acc
vhigh med 2 4 big med acc
vhigh med 2 4 big high acc
vhigh med 2 more med med unacc
vhigh med 3 4 small low unacc
vhigh med 3 4 med low unacc
vhigh med 3 4 med high acc
vhigh med 3 4 big med acc
vhigh med 3 more small high acc
vhigh med 3 more med low unacc
vhigh med 3 more med med acc
vhigh med 4 4 small low unacc
vhigh med 4 4 small med unacc
vhigh med 4 4 small high acc
vhigh med 4 more med med acc
vhigh med 4 more big low unacc
vhigh med 5more 2 med high unacc
vhigh med 5more 2 big low unacc
vhigh med 5more 2 big med unacc
vhigh med 5more 4 med med acc
vhigh med 5more 4 big med acc
vhigh med 5more more small high acc
vhigh med 5more more med low unacc
vhigh med 5more more big high acc
vhigh low 2 2 small high unacc
vhigh low 2 2 big low unacc
vhigh low 2 2 big med unacc
vhigh low 2 2 big high unacc
vhigh low 2 4 small high acc
vhigh low 2 4 big high acc
vhigh low 2 more small low unacc
vhigh low 2 more med high acc
vhigh low 2 more big med acc
vhigh low 3 2 small high unacc
vhigh low 3 2 med med unacc
vhigh low 3 2 med high unacc
vhigh low 3 4 small high acc
vhigh low 3 4 med low unacc
vhigh low 3 more small low unacc
vhigh low 3 more small high acc
vhigh low 4 2 small med unacc
vhigh low 4 2 big high unacc
vhigh low 4 4 med med acc
vhigh low 4 4 big med acc
vhigh low 4 more big high acc
vhigh low 5more 2 small high unacc
vhigh low 5more 2 med low unacc
vhigh low 5more 2 med med unacc
vhigh low 5more 4 small low unacc
vhigh low 5more 4 small med unacc
vhigh low 5more 4 small high acc
vhigh low 5more 4 med low unacc
vhigh low 5more more small low unacc
vhigh low 5more more med low unacc
vhigh low 5more more med med acc
vhigh low 5more more big high acc
high vhigh 2 2 small low unacc
high vhigh 2 2 med low unacc
high vhigh 2 2 big high unacc
high vhigh 2 4 med low unacc
high vhigh 2 4 med high unacc
high vhigh 2 4 big med unacc
high vhigh 2 more med med unacc
high vhigh 2 more big med unacc
high vhigh 2 more big high unacc
high vhigh 3 2 big med unacc
high vhigh 3 4 med high unacc
high vhigh 3 more small high unacc
high vhigh 3 more med med unacc
high vhigh 4 2 small low unacc
high vhigh 4 2 small med unacc
high vhigh 4 2 med med unacc
high vhigh 4 2 med high unacc
high vhigh 4 2 big low unacc
high vhigh 4 2 big high unacc
high vhigh 4 4 small med unacc
high vhigh 4 4 med med unacc
high vhigh 4 more med med unacc
high vhigh 4 more big low unacc
high vhigh 4 more big med unacc
high vhigh 5more 2 small med unacc
high vhigh 5more 2 med low unacc
high vhigh 5more 2 med med unacc
high vhigh 5more 4 small low unacc
high vhigh 5more 4 small med unacc
high vhigh 5more 4 small high unacc
high vhigh 5more 4 big low unacc
high vhigh 5more 4 big high unacc
high vhigh 5more more med med unacc
high vhigh 5more more med high unacc
high vhigh 5more more big low unacc
high vhigh 5more more big med unacc
high high 2 2 small high unacc
high high 2 2 big med unacc
high high 2 4 small low unacc
high high 2 4 small med unacc
high high 2 4 med low unacc
high high 2 4 big med acc
high high 2 more big low unacc
high high 2 more big high acc
high high 3 2 small low unacc
high high 3 2 med low unacc
high high 3 2 big low unacc
high high 3 2 big med unacc
high high 3 4 small low unacc
high high 3 more small med unacc
high high 3 more big low unacc
high high 3 more big med acc
high high 4 2 med high unacc
high high 4 2 big high unacc
high high 4 4 med low unacc
high high 4 4 med high acc
high high 4 more med high acc
high high 4 more big low unacc
high high 4 more big high acc
high high 5more 2 med med unacc
high high 5more 2 med high unacc
high high 5more 2 big high unacc
high high 5more 4 small low unacc
high high 5more 4 med low unacc
high high 5more 4 med high acc
high high 5more 4 big low unacc
high high 5more more small med unacc
high high 5more more big med acc
high med 2 2 med med unacc
high med 2 2 big high unacc
high med 2 4 small low unacc
high med 2 more med low unacc
high med 2 more med med unacc
high med 2 more big med acc
high med 3 2 big low unacc
high med 3 4 small low unacc
high med 3 4 med high acc
high med 3 4 big low unacc
high med 3 more med low unacc
high med 4 2 small low unacc
high med 4 2 med med unacc
high med 4 4 small low unacc
high med 4 4 small med unacc
high med 4 4 big low unacc
high med 4 more med high acc
high med 4 more big low unacc
high med 4 more big high acc
high med 5more 2 small med unacc
high med 5more 2 small high unacc
high med 5more 2 big med unacc
high med 5more 4 med low unacc
high med 5more 4 big med acc
high med 5more more small low unacc
high med 5more more small med unacc
high med 5more more med med acc
high med 5more more big med acc
high med 5more more big high acc
high low 2 2 small med unacc
high low 2 2 med med unacc
high low 2 4 big high acc
high low 2 more small high unacc
high low 3 2 small low unacc
high low 3 4 small low unacc
high low 3 4 small med unacc
high low 3 4 med low unacc
high low 3 4 med high acc
high low 3 more small low unacc
high low 3 more small high acc
high low 3 more med low unacc
high low 3 more big med acc
high low 3 more big high acc
high low 4 2 small high unacc
high low 4 2 big low unacc
high low 4 2 big high unacc
high low 4 4 small high acc
high low 4 4 med high acc
high low 4 4 big low unacc
high low 4 4 big med acc
high low 4 4 big high acc
high low 5more 2 med low unacc
high low 5more 2 med med unacc
high low 5more 2 med high unacc
high low 5more 2 big med unacc
high low 5more 2 big high unacc
high low 5more 4 small med unacc
high low 5more 4 med low unacc
high low 5more 4 big med acc
high low 5more more med low unacc
high low 5more more big low unacc
high low 5more more big high acc
med vhigh 2 2 small med unacc
med vhigh 2 2 small high unacc
med vhigh 2 2 med low unacc
med vhigh 2 2 med med unacc
med vhigh 2 2 big low unacc
med vhigh 2 4 small high acc
med vhigh 2 4 med low unacc
med vhigh 2 4 med med unacc
med vhigh 2 more med med unacc
med vhigh 2 more med high acc
med vhigh 3 2 med med unacc
med vhigh 3 2 big low unacc
med vhigh 3 2 big med unacc
med vhigh 3 2 big high unacc
med vhigh 3 4 small high acc
med vhigh 3 4 med high acc
med vhigh 3 4 big med acc
med vhigh 3 more small low unacc
med vhigh 3 more small med unacc
med vhigh 3 more med low unacc
med vhigh 3 more med high acc
med vhigh 4 2 big low unacc
med vhigh 4 4 small high acc
med vhigh 4 4 big low unacc
med vhigh 4 more med med acc
med vhigh 4 more med high acc
med vhigh 4 more big med acc
med vhigh 5more 2 small low unacc
med vhigh 5more 2 small high unacc
med vhigh 5more 2 med low unacc
med vhigh 5more 2 med med unacc
med vhigh 5more 2 big low unacc
med vhigh 5more 2 big high unacc
med vhigh 5more 4 small med unacc
med vhigh 5more 4 big high acc
med vhigh 5more more big high acc
med high 2 2 med high unacc
med high 2 4 med low unacc
med high 2 4 med high acc
med high 2 more small low unacc
med high 2 more small high unacc
med high 2 more med med unacc
med high 2 more med high acc
med high 2 more big high acc
med high 3 2 small high unacc
med high 3 4 small low unacc
med high 3 4 med med unacc
med high 3 4 med high acc
med high 3 4 big low unacc
med high 3 more small low unacc
med high 3 more small med unacc
med high 3 more med med acc
med high 3 more big med acc
med high 4 2 small low unacc
med high 4 2 big high unacc
med high 4 4 small low unacc
med high 4 4 small high acc
med high 4 4 med high acc
med high 4 4 big med acc
med high 4 more small low unacc
med high 4 more med med acc
med high 4 more big high acc
med high 5more 2 small med unacc
med high 5more 2 med med unacc
med high 5more 2 big med unacc
med high 5more 4 small low unacc
med high 5more 4 big low unacc
med high 5more 4 big high acc
med high 5more more small high acc
med high 5more more med low unacc
med high 5more more med high acc
med high 5more more big low unacc
med med 2 2 small low unacc
med med 2 2 small high unacc
med med 2 2 med low unacc
med med 2 4 med high acc
med med 2 more small med unacc
med med 2 more med med acc
med med 2 more big high vgood
med med 3 2 med high unacc
med med 3 2 big low unacc
med med 3 2 big med unacc
med med 3 2 big high unacc
med med 3 4 big med acc
med med 3 4 big high vgood
med med 3 more small low unacc
med med 3 more med high vgood
med med 4 2 small high unacc
med med 4 2 med low unacc
med med 4 2 med med unacc
med med 4 4 small med acc
med med 4 4 med med acc
med med 4 more med low unacc
med med 4 more med med acc
med med 4 more big med acc
med med 5more 2 small med unacc
med med 5more 2 med low unacc
med med 5more 2 big low unacc
med med 5more 4 med med acc
med med 5more 4 big low unacc
med med 5more 4 big high vgood
med med 5more more med high vgood
med med 5more more big high vgood
med low 2 2 small low unacc
med low 2 2 small high unacc
med low 2 2 med med unacc
med low 2 2 big low unacc
med low 2 4 small low unacc
med low 2 4 big high vgood
med low 2 more small low unacc
med low 2 more small med unacc
med low 2 more small high unacc
med low 2 more big low unacc
med low 3 2 big med unacc
med low 3 4 med med acc
med low 3 4 med high good
med low 3 more small low unacc
med low 3 more small high good
med low 3 more med med good
med low 3 more big high vgood
med low 4 2 big low unacc
med low 4 4 med med good
med low 4 4 big high vgood
med low 4 more small med acc
med low 4 more big low unacc
med low 5more 2 small low unacc
med low 5more 2 small med unacc
med low 5more 2 med low unacc
med low 5more 2 big med unacc
med low 5more 4 small high good
med low 5more 4 big low unacc
low vhigh 2 2 small low unacc
low vhigh 2 2 big high unacc
low vhigh 2 4 small low unacc
low vhigh 2 4 big high acc
low vhigh 2 more big high acc
low vhigh 3 2 med low unacc
low vhigh 3 2 med med unacc
low vhigh 3 2 med high unacc
low vhigh 3 2 big low unacc
low vhigh 3 2 big high unacc
low vhigh 3 4 small med unacc
low vhigh 3 4 med low unacc
low vhigh 3 4 med high acc
low vhigh 3 4 big low unacc
low vhigh 3 more small high acc
low vhigh 3 more big low unacc
low vhigh 4 2 big low unacc
low vhigh 4 4 small med unacc
low vhigh 4 4 med med acc
low vhigh 4 4 med high acc
low vhigh 4 4 big med acc
low vhigh 4 more small med unacc
low vhigh 5more 2 med med unacc
low vhigh 5more 4 small med unacc
low vhigh 5more 4 small high acc
low vhigh 5more 4 med low unacc
low vhigh 5more 4 med high acc
low vhigh 5more more small low unacc
low vhigh 5more more med high acc
low high 2 2 small high unacc
low high 2 2 big high unacc
low high 2 4 small med acc
low high 2 4 med low unacc
low high 2 4 med med acc
low high 2 4 med high acc
low high 2 4 big low unacc
low high 2 more small high unacc
low high 2 more med med acc
low high 2 more big med acc
low high 3 2 small low unacc
low high 3 2 small med unacc
low high 3 2 big low unacc
low high 3 2 big med unacc
low high 3 4 small low unacc
low high 3 4 big high vgood
low high 3 more small med acc
low high 3 more med med acc
low high 3 more big low unacc
low high 4 2 med low unacc
low high 4 2 med high unacc
low high 4 2 big low unacc
low high 4 4 small med acc
low high 4 4 med low unacc
low high 4 4 big high vgood
low high 4 more small med acc
low high 4 more small high acc
low high 4 more med med acc
low high 4 more big high vgood
low high 5more 2 small med unacc
low high 5more 4 small high acc
low high 5more 4 med low unacc
low high 5more 4 med med acc
low high 5more more small high acc
low high 5more more med high vgood
low high 5more more big high vgood
low med 2 2 small high unacc
low med 2 4 small low unacc
low med 2 4 med med acc
low med 2 more med low unacc
low med 2 more med med acc
low med 2 more med high good
low med 2 more big low unacc
low med 2 more big med good
low med 3 2 med high unacc
low med 3 2 big low unacc
low med 3 4 small low unacc
low med 3 4 small high good
low med 3 more small med acc
low med 3 more small high good
low med 3 more med low unacc
low med 3 more med high vgood
low med 3 more big high vgood
low med 4 2 big med unacc
low med 4 4 small med acc
low med 4 4 med med good
low med 4 4 med high vgood
low med 4 4 big med good
low med 4 more med low unacc
low med 4 more big med good
low med 5more 2 small med unacc
low med 5more 2 small high unacc
low med 5more 2 big high unacc
low med 5more 4 small low unacc
low med 5more 4 med high vgood
low med 5more 4 big low unacc
low med 5more more small low unacc
low med 5more more med med good
low low 2 2 small low unacc
low low 2 2 small med unacc
low low 2 2 med high unacc
low low 2 2 big med unacc
low low 2 4 small high good
low low 2 4 med low unacc
low low 2 4 big low unacc
low low 2 4 big high vgood
low low 2 more small low unacc
low low 2 more med med acc
low low 2 more med high good
low low 2 more big med good
low low 3 2 small high unacc
low low 3 2 med med unacc
low low 3 2 med high unacc
low low 3 2 big med unacc
low low 3 4 small med acc
low low 3 4 big low unacc
low low 3 more small med acc
low low 3 more small high good
low low 3 more med med good
low low 3 more big med good
low low 3 more big high vgood
low low 4 2 small low unacc
low low 4 2 small med unacc
low low 4 2 big low unacc
low low 4 4 small low unacc
low low 4 4 med low unacc
low low 4 4 med med good
low low 4 more small med acc
low low 4 more small high good
low low 4 more med med good
low low 4 more med high vgood
low low 4 more big high vgood
low low 5more 2 big med unacc
low low 5more more small med acc
low low 5more more small high good
nrow(tstdata)
## [1] 518

Ruffio is trying to predict the class variable our of 6 predictor variables. The training and testing data set also have a healthy number of entries, good dataset size.

A look at the distribution of class will tell us if the training data is balanced or not:

summary(trdata)
##    buying      maint       doors     persons     lug_boot    safety   
##  high :302   high :298   2    :298   2   :408   big  :403   high:403  
##  low  :298   low  :302   3    :302   4   :402   med  :391   low :407  
##  med  :301   med  :309   4    :313   more:400   small:416   med :400  
##  vhigh:309   vhigh:301   5more:297                                    
##    class    
##  acc  :263  
##  good : 46  
##  unacc:858  
##  vgood: 43

The data looks to be somewhat unbalanced in the class variable. The predictor variables look well distributed, but the class variable is laking samples with the ‘good’ and ‘vgood’ labels. Ruffio might want to consider some balancing techniques to pre-condition his data.

Models

We do not know what the data used in this analysis is for. Model performance can be measured by accuracy, but it will also be influenced by the use case. A model with high accuracy could be discarded because the number of false positives are too high. Bu in other situations, say in critical operations where the cost of missing a positive is too high, false positives might be preferred over false negatives. The cost of missing a class might be very high, so we are better off misclassifying. We can also view this using sensitivity and specificity.

For Ruffio we will discuss accuracy together with false positive and false negative results, within the context of the classifier type, sensitivity and specificity.

1-Ruffio’s first model logistic regression

Ruffio’s first model is a multinomial logistic regression model with 4 levels, one for each output class.

x<-tstdata[,1:6]
y<-tstdata[[7]]

if(!require(VGAM)) library(VGAM)
if(!require(caret)) library(caret)

vglm_model<-vglm(class~buying+maint+doors+persons+lug_boot+safety,family = "multinomial",data=car_eval)

vglm_class_probabilities<-predict(vglm_model,tstdata[,1:6],type="response")

vglm_predicted_class<-apply(vglm_class_probabilities,1,which.max)

vglm_pred<-c()
vglm_pred[which(vglm_predicted_class=="1")]<-levels(y)[1]
vglm_pred[which(vglm_predicted_class=="2")]<-levels(y)[2]
vglm_pred[which(vglm_predicted_class=="3")]<-levels(y)[3]
vglm_pred[which(vglm_predicted_class=="4")]<-levels(y)[4]

vglm_mtab<-table(vglm_pred,tstdata[[7]])
(vglm_cmx<-confusionMatrix(table(vglm_pred,tstdata[[7]])))
## Confusion Matrix and Statistics
## 
##          
## vglm_pred acc good unacc vgood
##     acc   106    4    15     0
##     good    3   17     0     0
##     unacc  10    0   337     0
##     vgood   2    2     0    22
## 
## Overall Statistics
##                                           
##                Accuracy : 0.9305          
##                  95% CI : (0.9051, 0.9509)
##     No Information Rate : 0.6795          
##     P-Value [Acc > NIR] : < 2.2e-16       
##                                           
##                   Kappa : 0.8566          
##                                           
##  Mcnemar's Test P-Value : NA              
## 
## Statistics by Class:
## 
##                      Class: acc Class: good Class: unacc Class: vgood
## Sensitivity              0.8760     0.73913       0.9574      1.00000
## Specificity              0.9521     0.99394       0.9398      0.99194
## Pos Pred Value           0.8480     0.85000       0.9712      0.84615
## Neg Pred Value           0.9618     0.98795       0.9123      1.00000
## Prevalence               0.2336     0.04440       0.6795      0.04247
## Detection Rate           0.2046     0.03282       0.6506      0.04247
## Detection Prevalence     0.2413     0.03861       0.6699      0.05019
## Balanced Accuracy        0.9141     0.86653       0.9486      0.99597
(vglm_accuracy<-sum(diag(vglm_mtab))/sum(vglm_mtab))
## [1] 0.9305019

Loggistic regression classifiers are based on a linear model, that is classes are devided using a linear hyperplanes. With an accuracy of 0.93, we can see how this model performs rather well. But all classes are not predicted the same. if for instance we are very concerned about making sure we do actually predict all the vgood classes, say this is a class that is very important to identify (the indicator to a desiece in medicine, or an indicator of a catastrophic failure in engineering), this is an extraimly goo classifier. We see how sensitivity for vgood is 1, the classifier actually identifies all the aoccurences of our class. It is true there are some false negatives for this class, specificity is a bit lower than 1, but it is still very high, we really only see 4 instances where occurences of other classes where label as vgood.

Performance isn’t the same for all classes. If good is a critical class to always identify, logistic regression isn’t doing such a great job. With a sensitivity of 0.74, we see 6 instances where this class was missed. Specificity is higher, with lower number of other class occurrences being mislabelled. But we are measuring performance from the point of view of not missing classifications. What this tell us with this kind of classifier is that it is hard to find a linear hyperplane to segregate this class. It can also be due to the lo number of this class occurrences in the dataset as described in the data analysis section.

2-Ruffio’s second model - LDA

if(!require(MASS)) library(MASS)
## Loading required package: MASS
lda_model<-lda(class~buying+maint+doors+persons+lug_boot+safety,data=car_eval)

lda_class_probabilities<-predict(lda_model,tstdata[,1:6],type="response")

(lda_cmx<-table(lda_class_probabilities$class,tstdata[[7]]))
##        
##         acc good unacc vgood
##   acc   107   12    25     9
##   good    5    9     0     0
##   unacc   9    0   327     0
##   vgood   0    2     0    13
lda_mtab<-table(lda_class_probabilities$class,tstdata[[7]])
(lda_accuracy<-sum(diag(lda_cmx))/sum(lda_cmx))
## [1] 0.8803089
 lda_cmx<-confusionMatrix(table(lda_class_probabilities$class,tstdata[[7]]))

LDA is a classifier based on covariance. So here instead of being able to separate classes with a hyperplane, we are more interested in the correlation of the classes in the dataset. In LDA we are trying to separate the classes in a lower dimension. The algorithm does dimension reduction and segregates the data in new lower dimension axis. Ruffio’s data has 4 classes, so LDA will lower the dimension to 3, which allows us to visualize the data in a plot. We can see below how all classes are segregated in the lower dimension. The reduced accuracy tells us that it is harder to make this separation. In the plot we also see how two classes are misrepresented with very few instances.

library("scatterplot3d")

df<-as.data.frame(lda_class_probabilities$x)
colors <- c("#56B4E9", "#E69F00","#E694E9","#ABBBB9")
yhat<-as.numeric(lda_class_probabilities$class)
colors <- colors[as.numeric(yhat)]
scatterplot3d(df$LD1,df$LD3,df$LD3,color = colors)

As before, if vgood is an important class, this classifier doesn’t perform as good as the previous. Here we see 9 classification of vgood that were mislabel as something else. The same is true for our good class, where many instances of the class where labelled incorrectly.

3-Ruffio’s third model - decision trees

if(!require(rpart)) library(rpart)
## Loading required package: rpart
if(!require(rpart.plot)) library(rpart.plot)
## Loading required package: rpart.plot
if(!require(randomForest)) library(randomForest)
## Loading required package: randomForest
## randomForest 4.6-14
## Type rfNews() to see new features/changes/bug fixes.
## 
## Attaching package: 'randomForest'
## The following object is masked from 'package:ggplot2':
## 
##     margin
rpart_model<-rpart(class~buying+maint+doors+persons+lug_boot+safety,data=car_eval)

rpart_class_probabilities<-predict(rpart_model,tstdata[,1:6],type="class")

(rpart_mtab<-table(rpart_class_probabilities,tstdata[[7]]))
##                          
## rpart_class_probabilities acc good unacc vgood
##                     acc   106    0    14     5
##                     good   10   20     1     0
##                     unacc   4    0   337     0
##                     vgood   1    3     0    17
rpart_cmx<-confusionMatrix(rpart_mtab)
(rpart_accuracy<-sum(diag(rpart_mtab))/sum(rpart_mtab))
## [1] 0.9266409

With this classifier we are now looking at separating the data using thresholds that break the data into smaller groups until we can classify all the instances. So here we start by calculating the probability of an entry being in one group versus all others, and then continue the process until all points are classified. Ruffio can actually plot this classification, and see how well the points are being assigned.

library(rpart.plot)
library(RColorBrewer)
library(rattle)
## Rattle: A free graphical interface for data science with R.
## Version 5.3.0 Copyright (c) 2006-2018 Togaware Pty Ltd.
## Type 'rattle()' to shake, rattle, and roll your data.
## 
## Attaching package: 'rattle'
## The following object is masked from 'package:randomForest':
## 
##     importance
## The following object is masked from 'package:VGAM':
## 
##     wine
fancyRpartPlot(rpart_model,caption=NULL)

We see that this classifier has better accuracy that the previous, but again not as good as logistic regression. We also find that if being able to classify all possible vgood instances, then again the first algorithm shows the best results, as this one misses 5 instances of this class.

4-Ruffio’s bagging classifier

So far Ruffio’s has been working on single models. Now he has moved to look at more complex approaches where many models are combined in an ensemble. These classifier might show better results, unless Occam’s Razor’s applies an a simpler model is better.

#bagging
if(!require(ipred)) library(ipred)
## Loading required package: ipred
bag_model<-bagging(class~buying+maint+doors+persons+lug_boot+safety,data=car_eval)

bag_class_probabilities<-predict(bag_model,tstdata[,1:6])#,type="response")

bag_mtab<-table(bag_class_probabilities,tstdata[[7]])
(bag_cmx<-confusionMatrix(bag_mtab))
## Confusion Matrix and Statistics
## 
##                        
## bag_class_probabilities acc good unacc vgood
##                   acc   114    2     3     1
##                   good    2   20     1     0
##                   unacc   5    0   348     0
##                   vgood   0    1     0    21
## 
## Overall Statistics
##                                           
##                Accuracy : 0.971           
##                  95% CI : (0.9527, 0.9837)
##     No Information Rate : 0.6795          
##     P-Value [Acc > NIR] : < 2.2e-16       
##                                           
##                   Kappa : 0.9395          
##                                           
##  Mcnemar's Test P-Value : NA              
## 
## Statistics by Class:
## 
##                      Class: acc Class: good Class: unacc Class: vgood
## Sensitivity              0.9421     0.86957       0.9886      0.95455
## Specificity              0.9849     0.99394       0.9699      0.99798
## Pos Pred Value           0.9500     0.86957       0.9858      0.95455
## Neg Pred Value           0.9824     0.99394       0.9758      0.99798
## Prevalence               0.2336     0.04440       0.6795      0.04247
## Detection Rate           0.2201     0.03861       0.6718      0.04054
## Detection Prevalence     0.2317     0.04440       0.6815      0.04247
## Balanced Accuracy        0.9635     0.93175       0.9793      0.97626
(bag_accuracy<-sum(diag(bag_mtab))/sum(bag_mtab))
## [1] 0.9710425

Looking at the results we observe a much better accuracy compared to previous classifiers. At 0.98, this is the best accuracy Ruffio has been able to get. But if again being able to label all instances of vgood, we see that sensitivity for this class is less than 1, as he obtained with the logistic regression. Although we only mis label 1 vgood. The other class we looked at, good, on the other hand shows a sensitivity of 1, so we manage to label all instances of this class. Again we are looking at the analysis as if these are the most important classes, so we do not rank the classifier on specificity necesarily.

Bagging is an enssemble method in which the data is sampled with replacement (bootstrap), it is used to train a classifier. This is done several times, and the results of all the models is combined into a simgle solution (aggreation). The final classification is taken as a simple vote of the different classifications. When running bagging on regressions, the results are averaged. Many classifiers can be used, but in this case Rffio is aggregating decision trees. So this model is somewhat equivalent to running the previous model several times and then aggregating the results. As expected a better accuracy is derived by this aggregation.

5-Ruffio’s boosting classifier

Next Ruffio has tried a gradient boosting algorithm. This is another kind on ensemble algorithm in which several model are combined, but instead of running the model is parallel and then combining results, here model are run in series, which each output serving as an input to the next. Which each new run of the clssifier, the results are improved. Also, each classifiers performance can actually be rather low (shallow trees can be used for example), and whith feeding the results to a new classifier, the overall effect is an improved performance.

nlev<-4 # number of classes
if(!require(gbm)) library(gbm)
## Loading required package: gbm
## Loaded gbm 2.1.5
gbm_model<-gbm(class~buying+maint+doors+persons+lug_boot+safety,    
  data=car_eval,
  n.trees=5000,
  interaction.depth=nlev,
    shrinkage=0.001,
  bag.fraction=0.8,
  distribution="multinomial",
  verbose=FALSE,
  n.cores=4)
gbm_class_probabilities<-predict(gbm_model,tstdata[,1:6],n.trees=5000,type="response")
gbm_pred<-apply(gbm_class_probabilities,1,which.max)

gbm_predicted_class<-unlist(lapply(gbm_pred,FUN=function(x)levels(tstdata[[7]])[[x]]))

(gbm_mtab<-table(gbm_predicted_class,tstdata[[7]]))
##                    
## gbm_predicted_class acc good unacc vgood
##               acc   115    0     5     1
##               good    4   20     1     0
##               unacc   2    0   346     0
##               vgood   0    3     0    21
(gbm_accuracy<-sum(diag(gbm_mtab))/sum(gbm_mtab))
## [1] 0.969112

As we can see, accuracy is again higher than our first set of classifiers, but slightly lower than our bagging model. Sensitivity is also in line with bagging, but not as good for the vgood class as our first logistic regression model. But interestingly, there are a couple of hyper-parameters in gradient boosting we can work with. GBM uses the gradient decent technique to find the classification of classes. The shrinkage hyper parameter controls the step of the gradient decent. SO a smaller step would require more iterations. Here we are doing 5000 steps, which seems like a lot. But if we actually run the classifier again with more steps we see accuracy increasing, an indication that gradient decent hasn’t found a minimal perhaps.

nlev<-4 # number of classes
if(!require(gbm)) library(gbm)
gbm_model<-gbm(class~buying+maint+doors+persons+lug_boot+safety,    
  data=car_eval,
  n.trees=20000,
  interaction.depth=nlev,
    shrinkage=0.001,
  bag.fraction=0.8,
  distribution="multinomial",
  verbose=FALSE,
  n.cores=4)
gbm_class_probabilities<-predict(gbm_model,tstdata[,1:6],n.trees=20000,type="response")
gbm_pred<-apply(gbm_class_probabilities,1,which.max)

gbm_predicted_class<-unlist(lapply(gbm_pred,FUN=function(x)levels(tstdata[[7]])[[x]]))

(gbm_mtab<-table(gbm_predicted_class,tstdata[[7]]))
##                    
## gbm_predicted_class acc good unacc vgood
##               acc   119    2     1     0
##               good    2   21     1     0
##               unacc   0    0   350     0
##               vgood   0    0     0    22
(gbm_accuracy<-sum(diag(gbm_mtab))/sum(gbm_mtab))
## [1] 0.988417

In fact, we can run with a smaller shrinkage or step and find even better accuracy.

nlev<-4 # number of classes
if(!require(gbm)) library(gbm)
gbm_model<-gbm(class~buying+maint+doors+persons+lug_boot+safety,    
  data=car_eval,
  n.trees=5000,
  interaction.depth=nlev,
    shrinkage=0.1,
  bag.fraction=0.8,
  distribution="multinomial",
  verbose=FALSE,
  n.cores=4)
gbm_class_probabilities<-predict(gbm_model,tstdata[,1:6],n.trees=5000,type="response")
gbm_pred<-apply(gbm_class_probabilities,1,which.max)

gbm_predicted_class<-unlist(lapply(gbm_pred,FUN=function(x)levels(tstdata[[7]])[[x]]))

(gbm_mtab<-table(gbm_predicted_class,tstdata[[7]]))
##                    
## gbm_predicted_class acc good unacc vgood
##               acc   121    3     0     0
##               good    0   20     1     1
##               unacc   0    0   351     0
##               vgood   0    0     0    21
(gbm_accuracy<-sum(diag(gbm_mtab))/sum(gbm_mtab))
## [1] 0.9903475

But increasing the step needs to be done with caution. Changing this parameter will also affect regularization, or the amount of overfitting of the model.

We rerun his original gbm model since he will use it in later models.

nlev<-4 # number of classes
if(!require(gbm)) library(gbm)
gbm_model<-gbm(class~buying+maint+doors+persons+lug_boot+safety,    
  data=car_eval,
  n.trees=5000,
  interaction.depth=nlev,
    shrinkage=0.001,
  bag.fraction=0.8,
  distribution="multinomial",
  verbose=FALSE,
  n.cores=4)
gbm_class_probabilities<-predict(gbm_model,tstdata[,1:6],n.trees=5000,type="response")
gbm_pred<-apply(gbm_class_probabilities,1,which.max)

gbm_predicted_class<-unlist(lapply(gbm_pred,FUN=function(x)levels(tstdata[[7]])[[x]]))

(gbm_mtab<-table(gbm_predicted_class,tstdata[[7]]))
##                    
## gbm_predicted_class acc good unacc vgood
##               acc   115    0     5     1
##               good    4   20     1     0
##               unacc   2    0   346     0
##               vgood   0    3     0    21
(gbm_accuracy<-sum(diag(gbm_mtab))/sum(gbm_mtab))
## [1] 0.969112

6-Ruffio’s second ensamble boosting classifier

Now he will rerun gradient boosting and combine the results with a first run. This is similar to what is done in bagging, but instead of combining several bootstraped model, he is combining results of boosting ensembles.

gbm_model2<-gbm(class~buying+maint+doors+persons+lug_boot+safety,
                data=car_eval,
                n.trees=5000,
                interaction.depth=nlev,
                shrinkage=0.001,
                bag.fraction=0.8,
                distribution="multinomial",
                verbose=FALSE,
                n.cores=4)
gbm_class_probabilities2<-predict(gbm_model2,tstdata[,1:6],n.trees=5000,type="response")
gbm_pred2<-apply(gbm_class_probabilities2,1,which.max)
gbm_pred2[which(gbm_pred2=="1")]<-levels(tstdata[[7]])[1]
gbm_pred2[which(gbm_pred2=="2")]<-levels(tstdata[[7]])[2]
gbm_pred2[which(gbm_pred2=="3")]<-levels(tstdata[[7]])[3]
gbm_pred2[which(gbm_pred2=="4")]<-levels(tstdata[[7]])[4]
gbm_pred2<-as.factor(gbm_pred2)
l<-union(gbm_pred2,tstdata[[7]])
(gbm_mtab2<-table(factor(gbm_pred2,l),factor(tstdata[[7]],l)))
##        
##         unacc acc vgood good
##   unacc   346   2     0    0
##   acc       5 115     1    0
##   vgood     0   0    21    3
##   good      1   4     0   20
(gbm_accuracy2<-sum(diag(gbm_mtab2))/sum(gbm_mtab2))
## [1] 0.969112
(gbm_cmx2<-confusionMatrix(gbm_mtab2))
## Confusion Matrix and Statistics
## 
##        
##         unacc acc vgood good
##   unacc   346   2     0    0
##   acc       5 115     1    0
##   vgood     0   0    21    3
##   good      1   4     0   20
## 
## Overall Statistics
##                                           
##                Accuracy : 0.9691          
##                  95% CI : (0.9503, 0.9822)
##     No Information Rate : 0.6795          
##     P-Value [Acc > NIR] : < 2.2e-16       
##                                           
##                   Kappa : 0.9363          
##                                           
##  Mcnemar's Test P-Value : NA              
## 
## Statistics by Class:
## 
##                      Class: unacc Class: acc Class: vgood Class: good
## Sensitivity                0.9830     0.9504      0.95455     0.86957
## Specificity                0.9880     0.9849      0.99395     0.98990
## Pos Pred Value             0.9943     0.9504      0.87500     0.80000
## Neg Pred Value             0.9647     0.9849      0.99798     0.99391
## Prevalence                 0.6795     0.2336      0.04247     0.04440
## Detection Rate             0.6680     0.2220      0.04054     0.03861
## Detection Prevalence       0.6718     0.2336      0.04633     0.04826
## Balanced Accuracy          0.9855     0.9676      0.97425     0.92973

As expected the performance doesn’t really change. This is becouse he is combining essentially the results of the same model, with the same data. SO its a combination, votes, of the same result.

7-Ruffio’s third tree ensamble classifier

Interestingly he decides to do this yet again and combine again the same boosting model. But now he increases the nlev to the number of classes (4) plus 1, for a total of 5. This hyper-parameter defines the depth of the decision trees in the ensemble. Deeper trees should perform better. In boosting we can use rather shallow trees, and by feeding the output of each to the next, the overall performance will be good.

nlev<-5 # number of classes+1
gbm_model3<-gbm(class~buying+maint+doors+persons+lug_boot+safety,   
          data=car_eval,
          n.trees=5000,
          interaction.depth=nlev,
            shrinkage=0.001,
          bag.fraction=0.8,
          distribution="multinomial",
          verbose=FALSE,
          n.cores=4)
gbm_class_probabilities3<-predict(gbm_model3,tstdata[,1:6],n.trees=5000,type="response")
gbm_pred3<-apply(gbm_class_probabilities3,1,which.max)

gbm_predicted_class3<-unlist(lapply(gbm_pred3,FUN=function(x)levels(tstdata[[7]])[[x]]))

(gbm_mtab3<-table(gbm_predicted_class3,tstdata[[7]]))
##                     
## gbm_predicted_class3 acc good unacc vgood
##                acc   117    1     4     1
##                good    3   19     1     0
##                unacc   1    0   347     0
##                vgood   0    3     0    21
(gbm_accuracy3<-sum(diag(gbm_mtab3))/sum(gbm_mtab3))
## [1] 0.972973
(gbm_cmx3<-confusionMatrix(gbm_mtab3))
## Confusion Matrix and Statistics
## 
##                     
## gbm_predicted_class3 acc good unacc vgood
##                acc   117    1     4     1
##                good    3   19     1     0
##                unacc   1    0   347     0
##                vgood   0    3     0    21
## 
## Overall Statistics
##                                           
##                Accuracy : 0.973           
##                  95% CI : (0.9551, 0.9851)
##     No Information Rate : 0.6795          
##     P-Value [Acc > NIR] : < 2.2e-16       
##                                           
##                   Kappa : 0.9442          
##                                           
##  Mcnemar's Test P-Value : NA              
## 
## Statistics by Class:
## 
##                      Class: acc Class: good Class: unacc Class: vgood
## Sensitivity              0.9669     0.82609       0.9858      0.95455
## Specificity              0.9849     0.99192       0.9940      0.99395
## Pos Pred Value           0.9512     0.82609       0.9971      0.87500
## Neg Pred Value           0.9899     0.99192       0.9706      0.99798
## Prevalence               0.2336     0.04440       0.6795      0.04247
## Detection Rate           0.2259     0.03668       0.6699      0.04054
## Detection Prevalence     0.2375     0.04440       0.6718      0.04633
## Balanced Accuracy        0.9759     0.90900       0.9899      0.97425

As expected he obtains a better accuracy, but not by very much. Using deeper trees means result from model to model are better. As before sensitivity to the vgood class shows the classifier has missed some labels, but not many only 1. SO performance is slightly better than our very first model, but we might still pick a model with better vgood sensitivity if that is what we are after.

8-Ruffio’s random forrest classifier

He now tries a random forrest, which is also an ensemble method using decision trees. The difference is that random forests train each tree independently with a random sample of the data. This randomness helps making the model less likely to overfitting. This more generalized approach probably means it shows less performance.

if(!require(randomForest))require(randomForest)
rf_model<-randomForest(class~buying+maint+doors+persons+lug_boot+safety,
data=car_eval)
rf_pred<-predict(rf_model,tstdata[,1:6])
rf_mtab<-table(rf_pred,tstdata[[7]])
rf_cmx<-confusionMatrix(rf_mtab)
rf_cmx$overall
##       Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull 
##   9.575290e-01   9.118421e-01   9.364022e-01   9.731953e-01   6.795367e-01 
## AccuracyPValue  McnemarPValue 
##   2.602506e-56            NaN
rf_cmx$byClass
##              Sensitivity Specificity Pos Pred Value Neg Pred Value Precision
## Class: acc     0.9834711   0.9571788      0.8750000      0.9947644 0.8750000
## Class: good    0.6956522   1.0000000      1.0000000      0.9860558 1.0000000
## Class: unacc   0.9772727   0.9879518      0.9942197      0.9534884 0.9942197
## Class: vgood   0.7727273   0.9939516      0.8500000      0.9899598 0.8500000
##                 Recall        F1 Prevalence Detection Rate Detection Prevalence
## Class: acc   0.9834711 0.9260700 0.23359073     0.22972973           0.26254826
## Class: good  0.6956522 0.8205128 0.04440154     0.03088803           0.03088803
## Class: unacc 0.9772727 0.9856734 0.67953668     0.66409266           0.66795367
## Class: vgood 0.7727273 0.8095238 0.04247104     0.03281853           0.03861004
##              Balanced Accuracy
## Class: acc           0.9703250
## Class: good          0.8478261
## Class: unacc         0.9826123
## Class: vgood         0.8833394

Accuracy is as expected slightly lower than previous methods. In general boosting performs better than RF if parameters tuned carefully, as we saw when looking at these model.

9-Ruffio’s xgboost classifier

This is his last classifier type. Here he has tried a gradient boosted decision trees model designed for speed and performance. This model has several hyper-parameters, but not att affect performance. As before, with a boosting ensemble the depth of the trees is one that can be experimented with.

if(!require(xgboost)) library(xgboost)
## Loading required package: xgboost
## 
## Attaching package: 'xgboost'
## The following object is masked from 'package:rattle':
## 
##     xgboost
if(!require(Matrix)) library(Matrix)
## Loading required package: Matrix
trdatamx<-sparse.model.matrix(class~.-1,data=trdata)
tstdatamx<-sparse.model.matrix(class~.-1,data=tstdata)

xgb_model<-xgboost(data=trdatamx,label=trdata$class,max_depth = 2, 
eta = 1, nrounds = 2,nthread = 2, objective = "multi:softmax",num_class=5)
## [1]  train-merror:0.249587 
## [2]  train-merror:0.221488
xgb_pred <- predict(xgb_model,tstdatamx)
xgb_tab<-table( xgb_pred)
xgb_mtab<-table(xgb_pred,tstdata[[7]])
#xgb_cmx<-confusionMatrix(xgb_mtab)
#xgb_cmx$overall
#xgb_cmx$byClass


xgb_model4<-xgboost(data=trdatamx,label=trdata$class,max_depth = 4, 
eta = 1, nrounds = 3,nthread = 2, objective = "multi:softmax",num_class=5)
## [1]  train-merror:0.166116 
## [2]  train-merror:0.126446 
## [3]  train-merror:0.087603
 xgb_pred4 <- predict(xgb_model4,tstdatamx)
xgb_tab4<-table( xgb_pred4)
temp_xgb_tab4<-xgb_tab4

xgb_pred4[which(xgb_pred4=="1")]<-levels(y)[1]
xgb_pred4[which(xgb_pred4=="2")]<-levels(y)[2]
xgb_pred4[which(xgb_pred4=="3")]<-levels(y)[3]
xgb_pred4[which(xgb_pred4=="4")]<-levels(y)[4]
xgb_mtab4<-table(xgb_pred4,tstdata[[7]])
xgb_cmx4<-confusionMatrix(xgb_mtab4)
xgb_cmx4$overall
##       Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull 
##   8.648649e-01   7.167519e-01   8.323720e-01   8.931184e-01   6.795367e-01 
## AccuracyPValue  McnemarPValue 
##   1.626424e-22            NaN
xgb_cmx4$byClass
##              Sensitivity Specificity Pos Pred Value Neg Pred Value Precision
## Class: acc     0.8264463   0.8942065      0.7042254      0.9441489 0.7042254
## Class: good    0.4782609   0.9919192      0.7333333      0.9761431 0.7333333
## Class: unacc   0.9289773   0.8734940      0.9396552      0.8529412 0.9396552
## Class: vgood   0.4545455   0.9939516      0.7692308      0.9762376 0.7692308
##                 Recall        F1 Prevalence Detection Rate Detection Prevalence
## Class: acc   0.8264463 0.7604563 0.23359073     0.19305019           0.27413127
## Class: good  0.4782609 0.5789474 0.04440154     0.02123552           0.02895753
## Class: unacc 0.9289773 0.9342857 0.67953668     0.63127413           0.67181467
## Class: vgood 0.4545455 0.5714286 0.04247104     0.01930502           0.02509653
##              Balanced Accuracy
## Class: acc           0.8603264
## Class: good          0.7350900
## Class: unacc         0.9012356
## Class: vgood         0.7242485

Here he tried with rather shallow trees, max of 2. We see that the accuracy is actually lower than with simpler methods. Using more complex methods doesn’t seem to add much performance to Ruffio’s modeling.

10-Ruffio’s second xgboost classifier

As a last step, he tries the same model now with deeper trees.

xgb_model5<-xgboost(data=trdatamx,label=trdata$class,max_depth = 5, 
eta = 1, nrounds = 4,nthread = 2, objective = "multi:softmax",num_class=5)
## [1]  train-merror:0.140496 
## [2]  train-merror:0.085124 
## [3]  train-merror:0.056198 
## [4]  train-merror:0.036364
 xgb_pred5 <- predict(xgb_model5,tstdatamx)
table( xgb_pred5)
## xgb_pred5
##   1   2   3   4 
## 123  22 353  20
xgb_tab5<-table( xgb_pred5)
temp_xgb_tab5<-xgb_tab5

xgb_pred5[which(xgb_pred5=="1")]<-levels(y)[1]
xgb_pred5[which(xgb_pred5=="2")]<-levels(y)[2]
xgb_pred5[which(xgb_pred5=="3")]<-levels(y)[3]
xgb_pred5[which(xgb_pred5=="4")]<-levels(y)[4]
xgb_mtab5<-table(xgb_pred5,tstdata[[7]])
xgb_cmx5<-confusionMatrix(xgb_mtab5)
xgb_cmx5$overall
##       Accuracy          Kappa  AccuracyLower  AccuracyUpper   AccuracyNull 
##   9.362934e-01   8.667020e-01   9.116926e-01   9.557452e-01   6.795367e-01 
## AccuracyPValue  McnemarPValue 
##   3.656179e-46            NaN
xgb_cmx5$byClass
##              Sensitivity Specificity Pos Pred Value Neg Pred Value Precision
## Class: acc     0.9008264   0.9647355      0.8861789      0.9696203 0.8861789
## Class: good    0.7391304   0.9898990      0.7727273      0.9879032 0.7727273
## Class: unacc   0.9744318   0.9397590      0.9716714      0.9454545 0.9716714
## Class: vgood   0.7272727   0.9919355      0.8000000      0.9879518 0.8000000
##                 Recall        F1 Prevalence Detection Rate Detection Prevalence
## Class: acc   0.9008264 0.8934426 0.23359073     0.21042471           0.23745174
## Class: good  0.7391304 0.7555556 0.04440154     0.03281853           0.04247104
## Class: unacc 0.9744318 0.9730496 0.67953668     0.66216216           0.68146718
## Class: vgood 0.7272727 0.7619048 0.04247104     0.03088803           0.03861004
##              Balanced Accuracy
## Class: acc           0.9327810
## Class: good          0.8645147
## Class: unacc         0.9570954
## Class: vgood         0.8596041

As with the previous ensemble where he did similar changes to the three depth, he sees an increase in performance with accuracy showing higher. But the performance of the model is still at par with several of his earlier models.

Last word

Ruffio has tried many different classifier’s, and has even gone into experimenting with many of its parameters. But at the end what we see is that even the simples model performs very well. In line with Occan’s Razor, the simplest model can be used without the need to implement complicated and maybe intricate models that really produce similar results,