Optimization#

class HyperparameterTuning(method_name: str, description: str, plot_settings)[source]#

Bases: MeasureEvaluator

Perform hyperparameter tuning using grid or random search.

This evaluator provides comprehensive hyperparameter optimization capabilities using either grid search or random search methods. It supports visualization of tuning results for 1D, 2D, and multi-dimensionalparameter spaces using line plots, 3D surface plots, and parallel coordinate plots respectively.

Attributes:
namestr

The name of the evaluator, set to ‘hyperparameter_tuning’

primary_colorstr

Primary color for plot elements

secondary_colorstr

Secondary color for plot elements

accent_colorstr

Accent color for plot elements

categorical_columnsList[str]

List of categorical parameter columns for parallel coordinate plots

calculate_measures(model: BaseEstimator, method: str, X_train: DataFrame, y_train: Series, scorer: str, kf: int, num_rep: int, n_jobs: int, param_grid: Dict[str, Any]) BaseEstimator[source]#

Perform hyperparameter tuning using grid or random search.

Executes the actual hyperparameter search using scikit-learn’s GridSearchCV or RandomizedSearchCV based on the specified method.

Parameters:
modelbase.BaseEstimator

The model to be tuned

methodstr

The search method to use (“grid” or “random”)

X_trainpd.DataFrame

The training features

y_trainpd.Series

The training target values

scorerstr

The scoring metric to optimize

kfint

Number of folds for cross-validation

num_repint

Number of repetitions for cross-validation

n_jobsint

Number of parallel jobs to run

param_gridDict[str, Any]

The hyperparameter grid to search over

Returns:
base.BaseEstimator

The search result object containing best parameters and scores

Raises:
ValueError

If method is not “grid” or “random”

evaluate(model: BaseEstimator, method: str, X_train: DataFrame, y_train: Series, scorer: str, kf: int, num_rep: int, n_jobs: int, plot_results: bool = False, filename: str = 'hyperparameter_tuning') BaseEstimator[source]#

Perform hyperparameter tuning using grid or random search.

Executes hyperparameter optimization using the specified search method and returns the best model found. Optionally generates performance visualizations for the tuning results.

Parameters:
modelbase.BaseEstimator

The model to be tuned

methodstr

The search method to use (“grid” or “random”)

X_trainpd.DataFrame

The training features

y_trainpd.Series

The training target values

scorerstr

The scoring metric to optimize

kfint

Number of folds for cross-validation

num_repint

Number of repetitions for cross-validation

n_jobsint

Number of parallel jobs to run

plot_resultsbool, optional

Whether to generate performance plots, by default False

filenamestr, optional

Filename for saving plots, by default “hyperparameter_tuning”

Returns:
base.BaseEstimator

The tuned model with optimal hyperparameters

log_results(model: BaseEstimator) None[source]#

Log the results of the hyperparameter tuning.

Logs completion message for hyperparameter optimization process.

Parameters:
modelbase.BaseEstimator

The model that was tuned

Returns:
None