base_trainer
BaseTrainer
Base trainer class for model training.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
np.ndarray or torch.Tensor
|
Input data of shape (num_samples, num_features). |
required |
y |
np.ndarray or torch.Tensor
|
Target data of shape (num_samples,). |
required |
sample_weights |
np.ndarray or torch.Tensor
|
Optional sample weights of shape (num_samples,). |
None
|
test_size |
float
|
The proportion of the data to include in the validation set. |
0.2
|
random_state |
int
|
The seed used by the random number generator. |
42
|
num_epochs |
int
|
Number of training epochs. |
50
|
batch_size |
int
|
Batch size for training. |
256
|
optimizer_fn_name |
str
|
Name of the optimizer function from the |
'Adam'
|
lr |
float
|
Learning rate for the optimizer. |
0.01
|
use_scheduler |
bool
|
Whether to use a learning rate scheduler ( |
False
|
patience |
int
|
Number of consecutive epochs with no improvement after which training will be stopped. |
10
|
dtype |
torch.dtype
|
Data type to use for the tensors. |
torch.float32
|
device |
torch.device
|
Device can be specified to the desired |
None
|
multi_cpu_dataloader |
bool
|
Use multiple CPUs for data loading or pass everything onto the GPU. |
True
|
Attributes:
Name | Type | Description |
---|---|---|
X |
torch.Tensor
|
Input data tensor. |
y |
torch.Tensor
|
Target data tensor. |
sample_weights |
torch.Tensor
|
Sample weights tensor. |
test_size |
float
|
Proportion of data to include in the validation set. |
random_state |
int
|
Seed used by the random number generator. |
num_epochs |
int
|
Number of training epochs. |
batch_size |
int
|
Batch size for training. |
optimizer_fn_name |
str
|
Name of the optimizer function. |
lr |
float
|
Learning rate for the optimizer. |
patience |
int
|
Number of consecutive epochs with no improvement after which training will be stopped. |
dtype |
torch.dtype
|
Data type of the tensors. |
train_loader |
torch.utils.data.DataLoader
|
DataLoader for training data. |
Source code in uncertaintyplayground/trainers/base_trainer.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
custom_lr_scheduler(epoch)
Custom learning rate scheduler function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch |
int
|
Current epoch. |
required |
Returns:
Name | Type | Description |
---|---|---|
float | Learning rate for the epoch. |
Source code in uncertaintyplayground/trainers/base_trainer.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
prepare_dataloader()
Prepare the DataLoader for training data.
Source code in uncertaintyplayground/trainers/base_trainer.py
140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
prepare_inputs()
Convert input data to the correct type and format.
Source code in uncertaintyplayground/trainers/base_trainer.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
split_data()
Split the data into training and validation sets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_size |
float
|
Proportion of data to include in the validation set. |
required |
Source code in uncertaintyplayground/trainers/base_trainer.py
111 112 113 114 115 116 117 118 119 120 121 122 123 |
|