autoqild.bayes_search.bayes_search_utilsΒΆ
Provides utility functions to support the hyperparameter tuning process, including callback mechanisms, parameter extraction, and scoring functions.
Functions
|
Convert a value to its appropriate type. |
|
Get the parameters and loss at the k-th position. |
|
Get the predicted probabilities and labels for the input samples. |
|
Callback function for logging parameters and scores during Bayesian optimization. |
|
Calibrate the predicted probabilities. |
|
Update the learner parameters with the best parameters at the k-th position. |
- autoqild.bayes_search.bayes_search_utils.convert_value(value)[source]ΒΆ
Convert a value to its appropriate type.
- Parameters:
value (str) β The value to be converted.
- Returns:
The converted value.
- Return type:
int, float, or str
Notes
This function tries to convert the value to an integer first. If it fails, it tries to convert it to a float. If it still fails, it returns the value as a string.
- autoqild.bayes_search.bayes_search_utils.get_parameters_at_k(optimizers, search_keys, k)[source]ΒΆ
Get the parameters and loss at the k-th position.
- Parameters:
optimizers (list of skopt.optimizer.Optimizer) β The list of optimizers.
search_keys (list of str) β The search keys for the parameters.
k (int) β The position to retrieve the parameters from.
- Returns:
best_loss (float) β The best loss at the k-th position.
best_params (dict) β The best parameters at the k-th position.
- autoqild.bayes_search.bayes_search_utils.get_scores(X, estimator)[source]ΒΆ
Get the predicted probabilities and labels for the input samples.
- Parameters:
X (array-like of shape (n_samples, n_features)) β Feature matrix.
estimator (estimator object) β The estimator to use for predictions.
- Returns:
p_pred (array-like of shape (n_samples, n_classes)) β Predicted class probabilities.
y_pred (array-like of shape (n_samples,)) β Predicted class labels.
- autoqild.bayes_search.bayes_search_utils.log_callback(parameters)[source]ΒΆ
Callback function for logging parameters and scores during Bayesian optimization.
- Parameters:
parameters (list of str) β The parameters to log.
- Returns:
on_step β The callback function.
- Return type:
callable
- autoqild.bayes_search.bayes_search_utils.probability_calibration(X_train, y_train, X_test, classifier, calibrator)[source]ΒΆ
Calibrate the predicted probabilities.
- Parameters:
X_train (array-like of shape (n_samples_train, n_features)) β Training feature matrix.
y_train (array-like of shape (n_samples_train,)) β Training target vector.
X_test (array-like of shape (n_samples_test, n_features)) β Test feature matrix.
classifier (estimator object) β The classifier to use for predictions.
calibrator (calibrator object) β The calibrator to use for calibration.
- Returns:
y_pred_cal β Calibrated predicted probabilities.
- Return type:
array-like of shape (n_samples_test, n_classes)
- autoqild.bayes_search.bayes_search_utils.update_params_at_k(bayes_search, search_keys, learner_params, k=0)[source]ΒΆ
Update the learner parameters with the best parameters at the k-th position.
- Parameters:
bayes_search (BayesSearchCV) β The BayesSearchCV instance.
search_keys (list of str) β The search keys for the parameters.
learner_params (dict) β The learner parameters to be updated.
k (int, default=0) β The position to retrieve the parameters from.
- Returns:
loss (float) β The best loss at the k-th position.
learner_params (dict) β The updated learner parameters.