Description Usage Arguments Value Examples
View source: R/NNetEarlyStoppingCV.R
This neral network algorithm has one output and one hidden layer, and uses cross validation to find the best step size corresponding to the max.iterations.
1 2 3 | NNetEarlyStoppingCV(X.mat, y.vec, fold.vec = sample(rep(1:n.folds, l =
length(y.vec))), max.iterations, step.size, n.hidden.units,
n.folds = 4L)
|
X.mat |
numeric feature matrix of size [n_observations x n_features]. |
y.vec |
numeric label vector of length n_observations. |
fold.vec |
numeric fold vector of length n_observations. |
max.iterations |
integer scalar greater than 1. |
step.size |
numeric positive scalar. |
n.hidden.units |
number of hidden units, greater than or equal to 1. |
n.folds |
positive integer scalar, numbers of folds, default is 4 |
result.list with named elements: pred.mat, n_observations x max.iterations matrix of predicted values. V.mat final weight matrix (n_features+1 x n.hidden.units). w.vec final weight vector (n.hidden.units+1). mean.validation.loss.vec mean loss for all validation sets. mean.train.loss.vec mean loss for all training sets. selected steps best step size selected corresponding to the minimum mean validation loss. predict(testX.mat) a function that takes a test features matrix and returns a vector of predictions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #Binary Classification:
library(NeuralNetwork)
data(spam, package = "ElemStatLearn")
X.mat = as.matrix(spam[, 1:57])
y.vec = ifelse(spam$spam == "spam", 1, -1)
result.list <- NNetEarlyStoppingCV(X.mat, y.vec, max.iterations = 30L, step.size = 0.02,
n.hidden.units = 100L, n.folds = 5L)
y.test <- ifelse(result.list$predict(X.mat[1:3,]) > 0.5, 1, -1)
#Linear Regression
library(NeuralNetwork)
data(ozone, package = "ElemStatLearn")
X.mat <- as.matrix(ozone[, -1])
y.vec <- as.vector(ozone[, 1])
result.list <- NNetEarlyStoppingCV(X.mat, y.vec, max.iterations = 30L, step.size = 0.02,
n.hidden.units = 100L, n.folds = 5L)
y.test <- result.list$predict(X.mat[1:3,])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.