我正在使用Keras,我想制作10个不同的训练和测试样本,以对这些样本重复拟合功能。
for (i in 1:10) {
## 75% of the sample size
smp_size <- floor(0.8 * nrow(cifarSmall$x))
## set the seed to make your partition reproducible
set.seed(123)
train_ind <- sample(seq_len(nrow(cifarSmall$x)), size = smp_size)
train_x <- cifarSmall$x[train_ind,,,]
train_y <- cifarSmall$y[train_ind]
test_x <- cifarSmall$x[-train_ind,,,]
test_y <- cifarSmall$y[-train_ind]
conjuntos_train_x[i] <- c(train_x)
}
答案 0 :(得分:0)
也许会进行10次交叉验证:
n <- 5
repeat <- 2
for(j in 1:repeat){
indexes <- split(sample(1:nrow(iris)),1:n)
for (i in 1:n) {
test_x <- iris[indexes[[i]],]
train_x <- iris[-indexes[[i]],]
## train, evaluate keras model
## do some hyper tuning
}
}
关于交叉验证的一件好事是,您假设训练集和测试集之间具有独立性,同时保留了大量训练数据。现在测试错误和指标是独立的,因此您可以假设i.i.d比较和调整模型。在输入数据中。
答案 1 :(得分:0)
也许这可以为您提供帮助,我只是对您的代码做了一些修改。
cifarSmall= data.frame(x=c(1,2,3,4),y=c(2,3,4,5),z=c(3,1,2,4))
conjuntos_train_x = list()
for (i in 1:10) {
## 75% of the sample size
smp_size <- floor(0.8 * nrow(cifarSmall))
## set the seed to make your partition reproducible
set.seed(i)
train_ind <- sample(1:nrow(cifarSmall),smp_size)
train_x <- cifarSmall[train_ind,-1]
train_y <- cifarSmall[train_ind,1]
conjuntos_train_x [i] <- data.frame(train_y,train_x)
}
conjuntos_train_x