uqregressors.tuning.tuning
Tuning contains the helper function tune_hyperparams which uses the Bayesian hyperparameter optimization framework, Optuna as well as some examples of potential scoring functions.
Important features of this hyperparameter optimization method are
- Customizable scoring function
- Customizable hyperparameters to be tuned
- Customizable number of tuning iterations, search space
- Support for cross-validation
interval_score(estimator, X, y)
Example of interval_score scoring function for hyperparameter tuning, greater=False
Source code in uqregressors\tuning\tuning.py
23 24 25 26 27 28 29 30 31 32 |
|
interval_width(estimator, X, y)
Example of minimizing interval width scoring function for hyperparameter tuning, greater=False
Source code in uqregressors\tuning\tuning.py
34 35 36 37 38 39 |
|
log_likelihood(estimator, X, y)
Example of maximizing log likelihood scoring function for hyperparameter tuning, greater=True
Source code in uqregressors\tuning\tuning.py
41 42 43 44 45 46 47 48 49 50 51 52 |
|
tune_hyperparams(regressor, param_space, X, y, score_fn, greater_is_better, n_trials=20, n_splits=3, random_state=42, verbose=True)
Optimizes a scikit-learn-style regressor using Optuna.
Supports CV when n_splits > 1, otherwise uses train/val split.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
regressor
|
BaseEstimator
|
An instance of a base regressor (must have .fit and .predict). |
required |
param_space
|
dict
|
Dict mapping param name → optuna suggest function (e.g., lambda t: t.suggest_float(...)). |
required |
X
|
Union[Tensor, ndarray, DataFrame, Series]
|
Training inputs. |
required |
y
|
Union[Tensor, ndarray, DataFrame, Series]
|
Training targets. |
required |
score_fn
|
Callable(estimator, X_val, y_val) → float
|
Scoring function. |
required |
greater_is_better
|
bool
|
Whether score_fn should be maximized (True) or minimized (False). |
required |
n_trials
|
int
|
Number of Optuna trials. |
20
|
n_splits
|
int
|
If >1, uses KFold CV; otherwise single train/val split. |
3
|
random_state
|
int
|
For reproducibility. |
42
|
verbose
|
bool
|
Print status messages. |
True
|
Returns:
Type | Description |
---|---|
Tuple[BaseEstimator, float, study]
|
A tuple containing the estimator with the optimized hyperparameters, the minimum score, and the optuna study object |
Source code in uqregressors\tuning\tuning.py
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 |
|