################################################################################# ################################################################################# ### Example R code ### VPR task ### Barbora Hladka, Martin Holub ### ESSLLI 2015 ### http://ufal.mff.cuni.cz/esslli2015 ################################################################################# ################################################################################# source("vpr.functions.R") library(rpart) library(adabag) cv.result.accuracy = numeric() for(fold in 1:FOLDS){ load.vpr.fold("cry", fold, verbose=T) remove.poor.features(fr.threshold=5, verbose=T) remove.identical.features(verbose=T) ### BOOSTING PARAMETERS boosting.mfinal = 500 boosting.boos = T prediction.range = seq(10, boosting.mfinal, 10) #prediction.range = 1:boosting.mfinal message("* Boosting iterations = ", boosting.mfinal, " \t [boos = ", boosting.boos, "]") model.ab <- boosting( tp ~ ., data=vpr.cv.train, mfinal = boosting.mfinal, boos = boosting.boos ) for( t in prediction.range ) { prediction.ab = predict( model.ab, newdata=vpr.cv.test, newmfinal=t, type="class" ) prediction = factor(prediction.ab$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#trees = ", prediction.range[i], "\t -- avg acc = ", round(sum(cv.result.accuracy[i,])/FOLDS * 100, 2), "\t\t CI radius = ",round(ci.radius(cv.result.accuracy[i,], 0.95) * 100, 2) ) } message("")