Model Evaluation: Cross-validation for regression task

rankings <- read.csv("~/Google Drive/CS539Proj6/Datasets/rank2010reducedforKKNN.csv", na.strings="NA")[-1] kfolds <- 10 # Number of folds for X-Validation index <- 1:nrow(rankings) index <- sample(index) ### shuffle index fold <- rep(1:kfolds, each=nrow(rankings)/kfolds)[1:nrow(rankings)] folds <- split(index, fold) ### create list with indices for each fold modeltime <- system.time(lm(acceptrate~.,train_kknn)) # test each fold lmSSE <- vector(mode="numeric") lmMSE <- vector(mode="numeric") lmCOR <- vector(mode="numeric") for(i in 1:length(folds)) { #cat("Calculating Fold: ",i,"\n") results <- lm(acceptrate~., rankings[-folds i,]) predicted <- predict(results, rankings[folds i,]) actualdata <- rankings$acceptrate[folds i] lmSSE[i] <- sum((predicted - actualdata)^2) lmMSE[i] <- mean((predicted - actualdata)^2) lmCOR[i] <- cor(predicted,actualdata) }  mean(lmSSE) mean(lmMSE) mean(lmCOR)
 * 1) Set-up k fold cross validation got this from Michael Hahslers Intro to Data Mining Book
 * 1) -- k fold cross validation for lm model