BaseTuner
Bases: BaseValidator
, ABC
Base class for implementing hyperparameter tuning strategies.
This class provides a framework for various hyperparameter optimization (HPO) strategies, supporting cross-validation (CV) and holdout tuning with options for binary and multiclass classification. Subclasses are expected to implement specific tuning methods, including holdout and CV procedures, while inheriting shared parameters, evaluation, and iteration logging functions.
Inherits
BaseValidator
: Validates instance-level variables.ABC
: Specifies abstract methods for subclasses to implement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
classification
|
str
|
The type of classification ('binary' or 'multiclass'). |
required |
criterion
|
str
|
The evaluation criterion (e.g., 'f1', 'brier_score'). |
required |
tuning
|
str
|
The tuning type ('holdout' or 'cv'). |
required |
hpo
|
str
|
The hyperparameter optimization method (e.g., 'random_search'). |
required |
n_configs
|
int
|
Number of configurations to evaluate during HPO. |
required |
n_jobs
|
int
|
Number of parallel jobs for model training. |
required |
verbose
|
bool
|
Enables detailed logs during tuning if True. |
required |
trainer
|
Optional[Trainer]
|
Trainer instance for evaluation. |
required |
mlp_training
|
bool
|
Enables MLP training with early stopping. |
required |
threshold_tuning
|
bool
|
Performs threshold tuning for binary classification if criterion is 'f1'. |
required |
Attributes:
Name | Type | Description |
---|---|---|
classification |
str
|
Type of classification ('binary' or 'multiclass'). |
criterion |
str
|
The performance criterion for optimization (e.g., 'f1', 'brier_score'). |
tuning |
str
|
Indicates the tuning approach ('holdout' or 'cv'). |
hpo |
str
|
Hyperparameter optimization method (e.g., 'random_search'). |
n_configs |
int
|
Number of configurations for HPO. |
n_jobs |
int
|
Number of parallel jobs for evaluation. |
verbose |
bool
|
Enables logs during tuning if True. |
mlp_training |
bool
|
Flag to enable MLP training with early stopping. |
threshold_tuning |
bool
|
Enables threshold tuning for binary classification. |
trainer |
Trainer
|
Trainer instance to handle model training and evaluation. |
Abstract Methods
cv
: Defines cross-validation strategy with or without tuning.holdout
: Implements holdout tuning on a validation set for selected hyperparameter configurations.
Source code in periomod/tuning/_basetuner.py
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
__init__(classification, criterion, tuning, hpo, n_configs, n_jobs, verbose, trainer, mlp_training, threshold_tuning)
¶
Initializes the base tuner class with common parameters.
Source code in periomod/tuning/_basetuner.py
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 |
|
cv(learner, outer_splits, racing_folds)
abstractmethod
¶
Perform cross-validation with optional tuning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learner
|
str
|
The model to evaluate. |
required |
outer_splits
|
List[Tuple[DataFrame, DataFrame]]
|
Train/validation splits. |
required |
racing_folds
|
Optional[int]
|
Number of racing folds; if None regular cross-validation is performed. |
required |
Source code in periomod/tuning/_basetuner.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
holdout(learner, X_train, y_train, X_val, y_val)
abstractmethod
¶
Perform random search on the holdout set for binary and multiclass .
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learner
|
str
|
The machine learning model used for evaluation. |
required |
X_train
|
DataFrame
|
Training features for the holdout set. |
required |
y_train
|
Series
|
Training labels for the holdout set. |
required |
X_val
|
DataFrame
|
Validation features for the holdout set. |
required |
y_val
|
Series
|
Validation labels for the holdout set. |
required |
Source code in periomod/tuning/_basetuner.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|