BaseExperiment
Bases: BaseValidator
, ABC
Base class for experiment workflows with model benchmarking.
This class provides a shared framework for setting up and running experiments with model training, resampling, tuning, and evaluation. It supports configurations for task-specific classification, tuning methods, hyperparameter optimization, and sampling strategies, providing core methods to set up tuning, training, and evaluation for different machine learning tasks.
Inherits
BaseValidator
: Validates instance-level variables and parameters.ABC
: Specifies abstract methods for subclasses to implement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The preloaded dataset used for training and evaluation. |
required |
task
|
str
|
Task name, used to determine the classification type based on the Can be 'pocketclosure', 'pocketclosureinf', 'improvement', or 'pdgrouprevaluation'. |
required |
learner
|
str
|
Specifies the machine learning model or algorithm to use for evaluation, including 'xgb', 'rf', 'lr' or 'mlp'. |
required |
criterion
|
str
|
Evaluation criterion for model performance. Options are 'f1' and 'macro_f1' for F1 score and 'brier_score' for Brier Score. |
required |
encoding
|
str
|
Encoding type for categorical features. Choose between 'one_hot' or 'target' encoding based on model requirements. |
required |
tuning
|
Optional[str]
|
The tuning method to apply during model training, either 'holdout' or 'cv' for cross-validation. |
required |
hpo
|
Optional[str]
|
Hyperparameter optimization strategy. Options include 'rs' (Random Search) and 'hebo'. |
required |
sampling
|
Optional[str]
|
Sampling strategy to address class imbalance in the dataset. Includes None, 'upsampling', 'downsampling', and 'smote'. |
required |
factor
|
Optional[float]
|
Factor used during resampling, specifying the amount of class balancing to apply. |
required |
n_configs
|
int
|
Number of configurations to evaluate during hyperparameter tuning, used to limit the search space. |
required |
racing_folds
|
Optional[int]
|
Number of racing folds used during random search for efficient hyperparameter optimization. |
required |
n_jobs
|
int
|
Number of parallel jobs to use for processing. Set to -1 to use all available cores. |
required |
cv_folds
|
int
|
Number of folds for cross-validation. |
required |
test_seed
|
int
|
Seed for random train-test split for reproducibility. |
required |
test_size
|
float
|
Proportion of data to use for testing. |
required |
val_size
|
float
|
Proportion of data to use for validation in a holdout strategy. |
required |
cv_seed
|
int
|
Seed for cross-validation splits for reproducibility. |
required |
mlp_flag
|
Optional[bool]
|
If True, enables training with a Multi-Layer
Perceptron (MLP) with early stopping. Defaults to |
required |
threshold_tuning
|
bool
|
If True, tunes the decision threshold in binary
classification to optimize for |
required |
verbose
|
bool
|
If True, enables detailed logging of the model training, tuning, and evaluation processes for better traceability. |
required |
Attributes:
Name | Type | Description |
---|---|---|
task |
str
|
The task name, used to set the evaluation objective. |
classification |
str
|
Classification type derived from the task ('binary' or 'multiclass') for configuring the evaluation. |
df |
DataFrame
|
DataFrame containing the dataset for training, validation, and testing purposes. |
learner |
str
|
The chosen machine learning model or algorithm for evaluation. |
encoding |
str
|
Encoding type applied to categorical features, either 'one_hot' or 'target'. |
sampling |
str
|
Resampling strategy used to address class imbalance in the dataset. |
factor |
float
|
Resampling factor applied to balance classes as per the chosen sampling strategy. |
n_configs |
int
|
Number of configurations evaluated during hyperparameter tuning. |
racing_folds |
int
|
Number of racing folds applied during random search for efficient tuning. |
n_jobs |
int
|
Number of parallel jobs used for model training and evaluation. |
cv_folds |
int
|
Number of folds used for cross-validation. |
test_seed |
int
|
Seed for splitting data into training and test sets, ensuring reproducibility. |
test_size |
float
|
Proportion of the dataset assigned to the test split. |
val_size |
float
|
Proportion of the dataset assigned to validation split in holdout validation. |
cv_seed |
int
|
Seed for cross-validation splits to ensure consistency across runs. |
mlp_flag |
bool
|
Enables training with a Multi-Layer Perceptron (MLP) and early stopping. |
threshold_tuning |
bool
|
Enables tuning of the classification threshold in binary classification for optimizing the F1 score. |
verbose |
bool
|
Controls the verbosity level of the output for detailed logs during training and evaluation. |
resampler |
Resampler
|
Instance of the |
trainer |
Trainer
|
Instance of the |
tuner |
Tuner
|
Instance of the |
Abstract Method
perform_evaluation
: Abstract method to handle the model evaluation process.
Source code in periomod/benchmarking/_basebenchmark.py
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
__init__(df, task, learner, criterion, encoding, tuning, hpo, sampling, factor, n_configs, racing_folds, n_jobs, cv_folds, test_seed, test_size, val_size, cv_seed, mlp_flag, threshold_tuning, verbose)
¶
Initialize the Experiment class with tuning parameters.
Source code in periomod/benchmarking/_basebenchmark.py
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 153 154 155 156 157 158 159 160 161 162 163 |
|
perform_evaluation()
abstractmethod
¶
Perform model evaluation and return final metrics.
Source code in periomod/benchmarking/_basebenchmark.py
235 236 237 |
|