################################################################################# ################################################################################# ### Example R code ### VPR task ### Barbora Hladka, Martin Holub ### ESSLLI 2015 ### http://ufal.mff.cuni.cz/esslli2015 ################################################################################# ################################################################################# source("vpr.functions.R") library(rpart) library(rpart.plot) cv.result.accuracy = numeric() for(fold in 1:FOLDS){ load.vpr.fold("cry", fold) remove.poor.features(5) model.dt <- rpart(tp ~ ., data=vpr.cv.train, method="class", cp=0.001) prediction = predict(model.dt, vpr.cv.test, type="class") conf.table = table(prediction, factor(vpr.cv.test$tp, levels = levels(prediction))) test.accuracy = sum(diag(conf.table))/nrow(vpr.cv.test) cv.result.accuracy = c(cv.result.accuracy, test.accuracy) message("\t acc = ", test.accuracy) message("") } cv.result.accuracy = matrix(cv.result.accuracy, ncol=FOLDS) message("\n*** Cross-validation results -- average accuracy ***") for(i in 1:nrow(cv.result.accuracy) ) { message("\t -- avg acc = ", sum(cv.result.accuracy[i,])/FOLDS, "\t\t CI radius = ",round(ci.radius(cv.result.accuracy[i,], 0.95) * 100, 2) ) } message("")