Trainer
- class seawrd.trainer.DNNTrainer(model_manager: DNNManager, config: SEAWRDConfig)
Bases:
objectA class to manage the training of a deep neural network (DNN) model. It can either load an existing model or generate a new one based on the provided parameters. The class also provides methods to generate callbacks for training and to print the architecture performance of the model.
- plot_loss_curve(log_y: bool = True, log_x: bool = True, max_y: float | None = None)
Plot the loss curve of the best model after training.
This method plots the training and validation losses over the epochs, providing a visual representation of the model’s learning process. The loss curve can help in diagnosing issues such as overfitting or underfitting and in understanding how well the model has learned from the training data.
- Parameters:
log_y (bool, optional) – Whether to use a logarithmic scale for the y-axis (loss values), by default True. This can be useful for visualizing loss values that span several orders of magnitude.
log_x (bool, optional) – Whether to use a logarithmic scale for the x-axis (epoch values), by default True. This can be useful for visualizing training progress over many epochs.
max_y (float, optional) – The maximum value for the y-axis (loss values), by default None. This can be useful for setting a fixed upper limit for the y-axis.
- print_architecture_performance()
Print the performance metrics of the model’s architecture, including the model name, number of parameters, and statistics about the training and validation losses. This method provides a quick overview of the model’s performance after training, allowing for easy comparison between different model architectures or training runs.
- train_models(input_features: ndarray | DataFrame, input_labels: ndarray | Series, test_features: ndarray | DataFrame, test_labels: ndarray | Series) tuple[ndarray, ndarray, ndarray, ndarray]
Train multiple models with different random initialisations and keep the best one based on validation loss. This method also collects statistics about each model’s performance.
- Parameters:
input_features (np.ndarray | pd.DataFrame) – The features of the input dataset, which will be used for training and validation.
input_labels (np.ndarray | pd.Series) – The labels of the input dataset, which will be split into training and validation sets based on the validation_split parameter.
test_features (np.ndarray | pd.DataFrame) – The features of the test dataset.
test_labels (np.ndarray | pd.Series) – The labels of the test dataset.
- Returns:
pred_means (np.ndarray) – The mean prediction errors for each model.
pred_stds (np.ndarray) – The standard deviation of prediction errors for each model.
losses (np.ndarray) – The training losses for each model.
val_losses (np.ndarray) – The validation losses for each model.