Learn R Programming

PDtoolkit (version 1.2.0)

kfold.idx: Indices for K-fold validation

Description

kfold.idx provides indices for K-fold validation.

Usage

kfold.idx(target, k = 10, type, seed = 2191)

Value

The command kfold.idx returns a list of k folds estimation and validation indices.

Arguments

target

Binary target variable.

k

Number of folds. If k is equal or greater than the number of observations of target variable, then validation procedure is equivalent to leave one out cross-validation (LOOCV) method. For stratified sampling, k is compared with frequencies of 0 and 1 from target. Default is set to 10.

type

Sampling type. Possible options are "random" and "stratified".

seed

Random seed needed for ensuring the result reproducibility. Default is 2191.

Examples

Run this code
suppressMessages(library(PDtoolkit))
data(loans)
#good-bad ratio
prop.table(table(loans$Creditability))
#random k-folds
kf.r <- kfold.idx(target = loans$Creditability, k = 5, type = "random", seed = 2191)
lapply(kf.r, function(x) prop.table(table(loans$Creditability[x[[2]]])))
#stratified k-folds
kf.s <- kfold.idx(target = loans$Creditability, k = 5, type = "stratified", seed = 2191)
lapply(kf.s, function(x) prop.table(table(loans$Creditability[x[[2]]])))

Run the code above in your browser using DataLab