
K-fold cross-validation.
CVHTF(X, y, K = 10, REP = 1, family = gaussian, ...)
training inputs
training output
size of validation sample
number of replications
glm family
optional arguments passed to glm
or lm
Vector of two components comprising the cross-validation MSE and its sd based on the MSE in each validation sample.
HTF (2009) describe K-fold cross-validation.
The observations are partitioned into K non-overlapping subsets of approximately
equal size. Each subset is used as the validation sample while the remaining
K-1 subsets are used as training data. When fold <- sample(rep(1:K,length=n))
.
Then fold
indicates each validation sample in the partition.
Hastie, T., Tibshirani, R. and Friedman, J. (2009). The Elements of Statistical Learning. 2nd Ed. Springer-Verlag.
# NOT RUN {
#Example 1. 10-fold CV
data(zprostate)
train<-(zprostate[zprostate[,10],])[,-10]
X<-train[,1:2]
y<-train[,9]
CVHTF(X,y,K=10,REP=1)[1]
# }
Run the code above in your browser using DataLab