【发布时间】:2021-04-03 01:03:40
【问题描述】:
我正在使用此代码和包splitTools:
library(splitTools)
set.seed(3451)
inds <- partition(iris$Sepal.Length, p = c(train = 0.8, test = 0.2))
train <- iris[inds$train,]
test <- iris[inds$test,]
folds <- create_folds(train$Sepal.Length, k = 5)
返回的对象 folds 是一个整数列表。是否可以将列折叠附加到包含折叠数(在本例中为 1、2、3、4 或 5)的数据框序列?谢谢。
PS:
悲惨的尝试:
results <- NULL
index <- 1
for (fold in folds) {
t <- train[-fold,]
t$fold <- index
index <- index + 1
results <- rbind(results, t)
}
table(results$fold)
train <- results
head(train)
【问题讨论】:
标签: r