trainind: Generation of Training Samples Indices

Description Usage Arguments Value Note Author(s) See Also Examples

Description

Generate training samples indices. The sampling scheme includes leave-one-out cross-validation (loocv), cross-validation (cv), randomised validation (random) and bootstrap (boot).

Usage

1
trainind(cl, pars = valipars())

Arguments

cl

A factor or vector of class.

pars

A list of sampling parameters for generating training index. It has the same structure as the output of valipars. See valipars for details.

Value

Returns a list of training indices.

Note

To avoid any errors when using subsequent classification techniques or others, training partitions contain at least two members of each class and prediction sets at least one sample of each class. Therefore, a minimum of 3 samples per class is required. As trainind is a fairly fast, hanging during the function may come from a low number of replicate in a class and/or the choice of an inadequate value (nreps).

Author(s)

Wanchang Lin [email protected]

See Also

valipars, accest

Examples

 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
## A trivia example
x <- as.factor(sample(c("a","b"), 20, replace=TRUE))
table(x)
pars <- valipars(sampling="rand", niter=2, nreps=4, strat=TRUE,div=2/3)
(temp <- trainind(x,pars=pars))
(tmp  <- temp[[1]])
x[tmp[[1]]];table(x[tmp[[1]]])     ## train idx
x[tmp[[2]]];table(x[tmp[[2]]])
x[tmp[[3]]];table(x[tmp[[3]]])
x[tmp[[4]]];table(x[tmp[[4]]])

x[-tmp[[1]]];table(x[-tmp[[1]]])   ## test idx
x[-tmp[[2]]];table(x[-tmp[[2]]])
x[-tmp[[3]]];table(x[-tmp[[3]]])
x[-tmp[[4]]];table(x[-tmp[[4]]])

# iris data set
data(iris)
dat <- subset(iris, select = -Species)
cl  <- iris$Species

## generate 5-fold cross-validation samples
cv.idx <- trainind(cl, pars = valipars(sampling="cv", niter=2, nreps=5))

## generate leave-one-out cross-validation samples
loocv.idx <- trainind(cl, pars = valipars(sampling = "loocv"))

## generate bootstrap samples with 25 replications
boot.idx <- trainind(cl, pars = valipars(sampling = "boot", niter=2,
                                           nreps=25))

## generate randomised samples with 1/4 division and 10 replications. 
rand.idx <- trainind(cl, pars = valipars(sampling = "rand", niter=2, 
                                           nreps=10, div = 1/4))

wilsontom/FIEmspro documentation built on Feb. 19, 2018, 9:03 a.m.