# NOT RUN {
### simple examples:
# preserves order, last two elements go into test set
H=holdout(1:10,ratio=2,internal=TRUE,mode="order")
print(H)
# no seed or NULL returns different splits:
H=holdout(1:10,ratio=2/3,mode="random")
print(H)
H=holdout(1:10,ratio=2/3,mode="random",seed=NULL)
print(H)
# same seed returns identical split:
H=holdout(1:10,ratio=2/3,mode="random",seed=12345)
print(H)
H=holdout(1:10,ratio=2/3,mode="random",seed=12345)
print(H)
### classification example
# }
# NOT RUN {
data(iris)
# random stratified holdout
H=holdout(iris$Species,ratio=2/3,mode="stratified")
print(table(iris[H$tr,]$Species))
print(table(iris[H$ts,]$Species))
M=fit(Species~.,iris[H$tr,],model="rpart") # training data only
P=predict(M,iris[H$ts,]) # test data
print(mmetric(iris$Species[H$ts],P,"CONF"))
# }
# NOT RUN {
### regression example with incremental and rolling window holdout:
# }
# NOT RUN {
ts=c(1,4,7,2,5,8,3,6,9,4,7,10,5,8,11,6,9)
d=CasesSeries(ts,c(1,2,3))
print(d) # with 14 examples
# incremental holdout example (growing window)
for(b in 1:4) # iterations
{
H=holdout(d$y,ratio=4,mode="incremental",iter=b,window=5,increment=2)
M=fit(y~.,d[H$tr,],model="mlpe",search=2)
P=predict(M,d[H$ts,])
cat("batch :",b,"TR from:",H$tr[1],"to:",H$tr[length(H$tr)],"size:",length(H$tr),
"TS from:",H$ts[1],"to:",H$ts[length(H$ts)],"size:",length(H$ts),
"mae:",mmetric(d$y[H$ts],P,"MAE"),"\n")
}
# rolling holdout example (sliding window)
for(b in 1:4) # iterations
{
H=holdout(d$y,ratio=4,mode="rolling",iter=b,window=5,increment=2)
M=fit(y~.,d[H$tr,],model="mlpe",search=2)
P=predict(M,d[H$ts,])
cat("batch :",b,"TR from:",H$tr[1],"to:",H$tr[length(H$tr)],"size:",length(H$tr),
"TS from:",H$ts[1],"to:",H$ts[length(H$ts)],"size:",length(H$ts),
"mae:",mmetric(d$y[H$ts],P,"MAE"),"\n")
}
# }
# NOT RUN {
### local seed simple example
# }
# NOT RUN {
# seed is defined, same sequence for N1 and N2:
# s2 generation sequence is not affected by the holdout call
set.seed(1); s1=sample(1:10,3)
set.seed(1);
N1=holdout(1:10,seed=123) # local seed
N2=holdout(1:10,seed=123) # local seed
print(N1$tr)
print(N2$tr)
s2=sample(1:10,3)
cat("s1:",s1,"\n")
cat("s2:",s2,"\n") # s2 is equal to s1
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab