NNetEarlyStoppingCV: a function using neurual network through cross validation

Description Usage Arguments Details Value Examples

View source: R/NN.R

Description

use K-fold cross validation based on the folds IDs provided in fold.vec(randomly)

Usage

1
2
3
4
5
6
7
8
9
NNetEarlyStoppingCV(
  X.mat,
  y.vec,
  fold.vec,
  max.iterations,
  step.size,
  n.hidden.units,
  n.folds = 4
)

Arguments

X.mat

: (n x p matrix of observations)

y.vec

: (vector with n labels that align with X.mat rows )

fold.vec

: (number of validation/training sets) fold.vec = samole(1:n.folds,length(y.vec))

max.iterations

(the maximum number of iterations for each fold)

step.size

(the step size used in the weighted gradient decent)

n.hidden.units

(the number of hidden units or "layer" to the net)

n.folds

(default = 4; this is the number of folds to be used to break data into folds Warning: make sure it is not too high or NULLS will cause failures)

Details

for each validarion/train split, use NNetIterations to compute the predictions for all observations

compute mean.validation.loss.vec, which is a vector(with max.iterations elements) of mean validation loss over all K folds

comput mean.train.loss.vec, analogous to above but for the train data

minimize the mean validation loss to determine selected.steps, the optimal number of steps/iterations

finally use NNetIteration(max.iterations=selected.steps) on the whole training data set

Value

mean.validation.loss

mean.train.loss.vec

selected.steps

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
Hard coded example
------------------
hardcv_incidence <- as.numeric(c(84.106289446623, 55.328513822534, 38.106289446623, 45.345737285, 24.324, 30.324))
hardcv_emission <- as.numeric(c(38.288719431206, 0.13392142633291, 4.573728543534, 23.737285372, 54.345, 14.4))
hardcv_phase <- as.numeric(c(120.59515694473, 55.329415379509, 100.1339214473, 154.9728542, 55.57, 47.00))

CVtestX.mat <- as.matrix(data.frame(hardcv_incidence, hardcv_emission, hardcv_phase))
CVtestY.vec <- as.numeric(c(0.0607816, 0.078306 , 0.098325, 0.052368, .0163620, 0.0757853))

# this line creates a fold vector with nfolds as the max number to be used
n.folds <- 2
fold.vec <- sample(rep(1:n.folds), length(CVtestY.vec),TRUE)
max.iterations <- 20L
step.size <- 0.2
n.hidden.units <- 12L

resultCV <- NNetEarlyStoppingCV(CVtestX.mat, CVtestY.vec, fold.vec, max.iterations, step.size, n.hidden.units, n.folds)
resultCV

ChaddFrasier/lunarLearningAlgorithms documentation built on May 17, 2020, 6:50 p.m.