Description Usage Arguments Value Examples
This function allows to create (un)stratified repeated folds from a label vector.
1 2 |
y |
Type: The label vector. |
n |
Type: integer. The amount of repeated fold computations to perform. Defaults to |
k |
Type: integer or vector of integers. The amount of folds to create. Causes issues if |
stratified |
Type: boolean. Whether the folds should be stratified (keep the same label proportions) or not. Defaults to |
seed |
Type: integer or vector of integers. The seed for the random number generator. If a vector of integer is provided, its length should be at least longer than |
named |
Type: boolean. Whether the folds should be named. Defaults to |
weight |
Type: boolean. Whether to return the weights of each fold so their sum is equal to |
A list of vectors for each fold, where an integer represents the row number, or a list of list containing Folds
and Weights
if weight = TRUE
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # Reproducible Stratified Repeated folds
data <- 1:5000
folds1 <- nkfold(y = data, n = 2, k = 5, stratified = TRUE, seed = 111)
folds2 <- nkfold(y = data, n = 2, k = 5, stratified = TRUE, seed = c(111, 112))
identical(folds1, folds2)
# Stratified Repeated Regression
data <- 1:5000
folds <- nkfold(y = data, n = 2, k = 5, stratified = TRUE)
for (i in 1:length(folds)) {
print(mean(data[folds[[i]]]))
}
# Stratified Repeated Multi-class Classification
data <- c(rep(0, 250), rep(1, 250), rep(2, 250))
folds <- nkfold(y = data, n = 2, k = 5, stratified = TRUE)
for (i in 1:length(folds)) {
print(mean(data[folds[[i]]]))
}
# Unstratified Repeated Regression
data <- 1:5000
folds <- nkfold(y = data, n = 2, k = 5, stratified = FALSE)
for (i in 1:length(folds)) {
print(mean(data[folds[[i]]]))
}
# Unstratified Repeated Multi-class Classification
data <- c(rep(0, 250), rep(1, 250), rep(2, 250))
folds <- nkfold(y = data, n = 2, k = 5, stratified = FALSE)
for (i in 1:length(folds)) {
print(mean(data[folds[[i]]]))
}
# Stratified Repeated 3-5-10 fold Cross-Validation all in one
data <- c(rep(0, 250), rep(1, 250), rep(2, 250))
str(nkfold(data, n = 3, k = c(3, 5, 10)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.