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_value(value)

Convert a value to its appropriate type.

get_parameters_at_k(optimizers, search_keys, k)

Get the parameters and loss at the k-th position.

get_scores(X, estimator)

Get the predicted probabilities and labels for the input samples.

log_callback(parameters)

Callback function for logging parameters and scores during Bayesian optimization.

probability_calibration(X_train, y_train, ...)

Calibrate the predicted probabilities.

update_params_at_k(bayes_search, ...[, k])

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.