hosa.models.rnn.rnn_models.BaseRNN
- class hosa.models.rnn.rnn_models.BaseRNN(n_outputs, n_neurons_dense_layer, n_units, n_subs_layers, is_bidirectional=False, model_type='lstm', optimizer='adam', dropout_percentage=0.1, activation_function_dense='relu', kernel_initializer='normal', batch_size=1000, epochs=50, patience=5, **kwargs)[source]
Bases:
objectBase class for Recurrent Neural Network (RNN) models for classification and regression.
Each RNN model comprises an input layer (an RNN or a bidirectional RNN cell),
n_subs_layerssubsequent layers (similar to the input cell), a dropout layer, a dense layer, and an output layer. The output layer is a dense layer withn_outputsunits, with the linear activation function.Warning
This class should not be used directly. Use derived classes instead, i.e.,
RNNClassificationorRNNRegression.Note
The parameters used in this library were adapted from the exact parameters of the TensorFlow library. Descriptions were thus modified accordingly to our approach. However, refer to the TensorFlow documentation for more details about each of those parameters.
- Parameters
n_outputs (int) – Number of class labels in classification, or the number of numerical values to predict in regression.
n_neurons_dense_layer (int) – Number of neurons units of the penultimate dense layer ( i.e., before the output layer).
n_units (int) – Dimensionality of the output space, i.e., the dimensionality of the hidden state.
n_subs_layers (int) – Number of subsequent recurrent layers beteween the input and output layers.
is_bidirectional (bool) – If
true, then bidirectional layers will be used to build the RNN model.model_type (str) – Type of RNN model to be used. Available options are
lstm, for a Long Short-Term Memory model, orgru, for a Gated Recurrent Unit model.optimizer (str) – Name of the optimizer. See tensorflow.keras.optimizers.
dropout_percentage (float) – Fraction of the input units to drop.
activation_function_dense (str) – Activation function to use on the penultimate dense layer. If not specified, no activation is applied (i.e., uses the linear activation function). See tensorflow.keras.activations.
kernel_initializer (str) – Initializer for the kernel weights matrix, used for the linear transformation of the inputs.
batch_size (int or None) – Number of samples per batch of computation. If
None,batch_sizewill default to 32.epochs (int) – Maximum number of epochs to train the model.
patience (int) – Number of epochs with no improvement after which training will be stopped.
**kwargs – Ignored. Extra arguments that are used for compatibility’s sake.
Methods
aux_fit(x, y, callback, validation_size[, ...])Auxiliar function for classification and regression models compatibility.
compile()Compiles the model for training.
fit(x, y, **kwargs)Fits the model to data matrix x and target(s) y.
predict(x, **kwargs)Predicts the target values using the input data in the trained model.
prepare(x, y)Prepares the model by adding the layers to the estimator: input layer,
n_subs_layerssubsequent layers, a dropout layer, a dense layer, and an output layer.score(x, y, **kwargs)Computes the performance metric(s) (e.g., accuracy for classification) on the given input data and target values.