buildRNN-method: Build RNN model

Description Usage Arguments Detail Examples

Description

buildRNN extends the class RS to SM.rnn by constructing and validating Keras models.

Usage

1
2
3
4
5
6
7
buildRNN(object, compile_options, hyperparameters, preprocess_method, lag,
  model_path)

## S4 method for signature 'RS,list,list,character,numeric,character'
buildRNN(object,
  compile_options, hyperparameters, preprocess_method = c("normalized",
  "maxmin"), lag, model_path)

Arguments

object

A RS class.

compile_options

A list contaning the follow compile options: optimizer, loss and metrics. In case of missing ones of those indicators, default values are setted automatically:

  • optimizer: adam

  • loss: mean_absolute_percentage_error

  • metrics: mean_absolute_percentage_error

. For more detail, check compile function of Keras.

hyperparameters

A list contaning the follow parameters of Keras model:

  • batch_size: Integer or NULL. Number of samples per gradient update. If unspecified, batch_size will default to 32,

  • epochs: Number of epochs to train the model. If unspecified, epochs will default to 10,

  • test_split: the percentage of trained data that goes to testing. Default value 0.3,

  • validation_split: the percentage of data that goes to validading model. Default value 0.3.

Note: a vector input is acceptable for each hyperparameter, in this case gridsearch will be applied.

preprocess_method

A character value indicating data preparation method, available methos are

  • normalized: normalization method using scale function,

  • maxmin: maximum minimum transformation.

lag

A integer value indicating how many previous data should be included in the data preparation process.

model_path

A string value indicating where should the model to be stored.

Detail

If lag is diferent a zero, the input data will be transformed to a new input with column number equal to 2x(lag + 1), named n_col. Once the data preparetion is done including the preprocess method, a Keras sequential model is constructed with following layers:

This model will be trained by first (1 - validation_split)% rows (the last test_split part to test the model) and validated by the last validations_split%. Once the model is done, it will be store to the model path because the S4 object can not treat the keras model as slot object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Not run: 
n <- 50
# An example to create the RS class.
 my_first_class <- RS(sigb = rnorm(n, mean = 0, sd = 1),
                      epsb = rnorm(n, mean = 0, sd = 2),
                      epsp = rnorm(n, mean = 1, sd = 1))
 compile_options <- list()
 hyperparameters <- list(batch_size = c(16, 32, 64),
 epochs = c(10, 20, 50))
 preprocess_method <- "maxmin"
 lag <- 5
 model_path <- "~/Desktop/pans_model"
 myRNN <- buildRNN(object = myclass, compile_options = list(), hyperparameters = hyperparameters,
 preprocess_method = preprocess_method, lag = lag, model_path = model_path)

## End(Not run)

4301350/sm4sd documentation built on June 14, 2020, 4:22 p.m.