Thursday, September 25, 2008
Here's the CV code we looked at tonight. I believe there was
something else I said I would post to the blog but now I can't remember...
numFolds <- 3 # how many of the possible 10 folds that are actually done
candidateBounds <- c(0.0001,0.001,0.005,0.01,0.03,0.07,0.1)
numCandidateBounds <- length(candidateBounds)
cvRMSE <- rep(0,numCandidateBounds)
cvIndex <- rep(1:10,trunc(nTrain/10)+1)[1:nTrain] # 1-10 repeated the rigtt # of times
cvIndex <- sample(cvIndex) # then scrambled
for (j in 1:numFolds) {
for (k in (1:numCandidateBounds)) {
# cat("fold:",j," candidate:",k,"\n")
mylm<-l1ce(y ~ .,data=fooTrain[cvIndex!=j,],bound=candidateBounds[k])
myPred<-predict(mylm,fooTrain[cvIndex==j,])
cvRMSE[k] <- cvRMSE[k] + sqrt(mean((fooTrain[cvIndex==j,]$y - myPred)^2))
}
}
k=1;
while ((cvRMSE[k] > (min(cvRMSE)-0.0000001)) && (k < numCandidateBounds)) {
k <- k+1;
}
if (k > 1) {k <- k-1} # back off one from the best
cat(candidateBounds[k],"\n")
something else I said I would post to the blog but now I can't remember...
numFolds <- 3 # how many of the possible 10 folds that are actually done
candidateBounds <- c(0.0001,0.001,0.005,0.01,0.03,0.07,0.1)
numCandidateBounds <- length(candidateBounds)
cvRMSE <- rep(0,numCandidateBounds)
cvIndex <- rep(1:10,trunc(nTrain/10)+1)[1:nTrain] # 1-10 repeated the rigtt # of times
cvIndex <- sample(cvIndex) # then scrambled
for (j in 1:numFolds) {
for (k in (1:numCandidateBounds)) {
# cat("fold:",j," candidate:",k,"\n")
mylm<-l1ce(y ~ .,data=fooTrain[cvIndex!=j,],bound=candidateBounds[k])
myPred<-predict(mylm,fooTrain[cvIndex==j,])
cvRMSE[k] <- cvRMSE[k] + sqrt(mean((fooTrain[cvIndex==j,]$y - myPred)^2))
}
}
k=1;
while ((cvRMSE[k] > (min(cvRMSE)-0.0000001)) && (k < numCandidateBounds)) {
k <- k+1;
}
if (k > 1) {k <- k-1} # back off one from the best
cat(candidateBounds[k],"\n")