The code presented here is from the final exam for the excellent JHU Machine Learning course offered through Coursera, which I took in the fall of 2015. First time I had to really get into the guts with R to configure an ML program more appropriately for the context of the problem. The modification was simple: we had unequal numbers of cases in each of the classes, so we had to downweight those classes with larger numbers of cases.
Worked out in the end, though -- I recall being one of only handful of students who correctly classified every case in the testing dataset :P .