CV_neural_network: Fit neural network, with parameter tuning via...

Description Usage Arguments Value Examples

View source: R/CV_interface.R

Description

Fit neural network, with parameter tuning via cross-validation on training set

Usage

1
2
3
CV_neural_network(train_X, train_y, test_X, test_y, n_hidden_layers = 1,
  hidden_layer_sizes = c(20), n_iterations = 100, step_size = 0.01,
  lambdas = c(5e-04, 0.001, 0.005, 0.01, 0.1), n_folds = 5, n_cores = 1)

Arguments

train_X

Matrix of training data (data points in rows, features in columns)

train_y

Vector of labels for training data (these have to be integers from 0 to n_classes - 1)

test_X

Matrix of test data

test_y

Vector of labels for test data

n_hidden_layers

Number of hidden layers in the neural network

hidden_layer_sizes

Vector containing the number of neurons in each hidden layer

n_iterations

The number of iterations for fitting the neural network

step_size

The step size for updating parameters at each iteration

lambdas

Vector of regularisation parameters (cross-validation is carried out over these)

n_cores

The number of parallel cores

Value

List containing the following elements: prob_test, pred_test

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
data(toy_data)
plot(toy_train$X, col=toy_train$y+1, pch=16)
res = CV_neural_network(toy_train$X, toy_train$y, toy_test$X, toy_test$y, n_iterations = 1000, step_size = 0.001)
res
# Confusion matrix for test data
table(res$pred_test, toy_test$y)

## Not run: 
data(mnist)
# Pick only first 500 data points (for speed)
res = CV_neural_network(train$x[1:500, ], train$y[1:500], test$x[1:250, ], test$y[1:250], n_iterations = 100, step_size = 0.0001)
table(res$pred_test, test$y[1:250])

## End(Not run)

mmider/OxWaSPneuralnets documentation built on May 23, 2019, 5:05 a.m.