Trains a feedforward neural network (FNN) model on the specified training dataset and makes predictions on the test dataset in a counterfactual scenario. The model uses meteorological variables and sin/cosine-transformed features. Scales the data before training and rescales predictions, as the model does not converge with unscaled data.
run_fnn(train, test, params, calc_shaps)A list with three elements:
dt_predictionsA data frame containing the test data along with the predicted values:
predictionThe predicted values from the FNN model.
prediction_lowerThe same predicted values, as no quantile model is available yet for FNN.
prediction_upperThe same predicted values, as no quantile model is available yet for FNN.
modelThe trained FNN model object from the
deepnet::nn.train() function.
importanceSHAP importance values (if
calc_shaps = TRUE). Otherwise, NULL.
A data frame or tibble containing the training dataset,
including the target variable (value)
and meteorological variables specified in params$meteo_variables.
A data frame or tibble containing the test dataset on which predictions will be made, using the same meteorological variables as in the training dataset.
A list of parameters that define the following:
A character vector specifying the names of the meteorological variables used as inputs.
A list of hyperparameters for training the feedforward neural network, including:
activation_fun: The activation function for the hidden
layers (e.g., "sigmoid", "tanh").
momentum: The momentum factor for training.
learningrate_scale: Factor for adjusting learning rate.
output_fun: The activation function for the output layer
batchsize: The size of the batches during training.
hidden_dropout: Dropout rate for the hidden layers to
prevent overfitting.
visible_dropout: Dropout rate for the input layer.
hidden_layers: A vector specifying the number of neurons
in each hidden layer.
num_epochs: Number of epochs (iterations) for training.
learning_rate: Initial learning rate.
Boolean value. If TRUE, calculate SHAP values for the
method used and format them so they can be visualised with
shapviz:sv_importance() and
shapviz:sv_dependence().
The SHAP values are generated for a subset (or all, depending on the size of the dataset) of the
test data.
This function provides flexibility for users with their own data pipelines
or workflows. For a simplified pipeline, consider using
run_counterfactual().
Experiment with hyperparameters such as learning_rate,
batchsize, hidden_layers, and num_epochs to improve
performance.
Warning: Using many or large hidden layers in combination with a high number of epochs can lead to long training times.
data(mock_env_data)
params <- load_params()
res <- run_fnn(
train = mock_env_data[1:80, ],
test = mock_env_data[81:100, ], params,
calc_shaps = FALSE
)
Run the code above in your browser using DataLab