HyperparameterSpaceBuilder#

The HyperparameterSpaceBuilder class provides tools to define and construct hyperparameter search spaces for optimization.

class mloptimizer.interfaces.HyperparameterSpaceBuilder[source]#

Bases: object

A builder class for constructing hyperparameter spaces.

This class is responsible for defining both fixed and evolvable hyperparameters, allowing for the construction of a HyperparameterSpace object used in optimization tasks.

Initializes the builder with empty dictionaries for both fixed and evolvable hyperparameters. Also initializes an instance of HyperparameterSpaceService to manage space-related operations.

add_categorical_param(name: str, values: list)[source]#

Adds a categorical parameter to the evolvable hyperparameters.

Parameters:
  • name (str) – The name of the hyperparameter.

  • values (list) – A list of categorical values that the parameter can take.

Returns:

self – The builder instance, allowing for method chaining.

Return type:

HyperparameterSpaceBuilder

add_float_param(name: str, min_value: int, max_value: int, scale=100)[source]#

Adds a float parameter to the evolvable hyperparameters.

Parameters:
  • name (str) – The name of the hyperparameter.

  • min_value (int) – The minimum value the parameter can take.

  • max_value (int) – The maximum value the parameter can take.

  • scale (int, optional) – Scaling factor for the float parameter (default is 100).

Returns:

self – The builder instance, allowing for method chaining.

Return type:

HyperparameterSpaceBuilder

add_int_param(name: str, min_value: int, max_value: int)[source]#

Adds an integer parameter to the evolvable hyperparameters.

Parameters:
  • name (str) – The name of the hyperparameter.

  • min_value (int) – The minimum value the parameter can take.

  • max_value (int) – The maximum value the parameter can take.

Returns:

self – The builder instance, allowing for method chaining.

Return type:

HyperparameterSpaceBuilder

build()[source]#

Builds the HyperparameterSpace object using the current configuration.

Returns:

The constructed hyperparameter space containing both fixed and evolvable parameters.

Return type:

HyperparameterSpace

static get_default_space(estimator_class)[source]#

Returns a default hyperparameter space using the HyperparameterSpaceService.

Parameters:

estimator_class (class) – The estimator class for which the default hyperparameter space should be retrieved.

Returns:

A default hyperparameter space for the given estimator class.

Return type:

HyperparameterSpace

load_default_space(estimator_class)[source]#

Load a default hyperparameter space using the HyperparameterSpaceService.

Parameters:

estimator_class (class) – The estimator class for which the default hyperparameter space should be loaded.

Returns:

A default hyperparameter space for the given estimator class.

Return type:

HyperparameterSpace

load_space(hyperparam_space_json_path)[source]#

Load a hyperparameter space from a JSON file using the HyperparameterSpaceService.

Parameters:

hyperparam_space_json_path (str) – The path to the JSON file containing the hyperparameter space.

Returns:

The loaded hyperparameter space.

Return type:

HyperparameterSpace

save_space(hyperparam_space, file_path, overwrite=False)[source]#

Save the hyperparameter space using the HyperparameterSpaceService.

Parameters:
  • hyperparam_space (HyperparameterSpace) – The hyperparameter space to be saved.

  • file_path (str) – The file path where the hyperparameter space should be saved.

  • overwrite (bool, optional) – Whether to overwrite an existing file (default is False).

Return type:

None

set_fixed_param(name: str, value)[source]#

Sets a fixed parameter with the given name and value.

Parameters:
  • name (str) – The name of the parameter.

  • value (any) – The fixed value to assign to the parameter.

Returns:

self – The builder instance, allowing for method chaining.

Return type:

HyperparameterSpaceBuilder

set_fixed_params(fixed_params: dict)[source]#

Sets multiple fixed parameters using a dictionary.

Parameters:

fixed_params (dict) – A dictionary where keys are parameter names and values are their fixed values.

Returns:

self – The builder instance, allowing for method chaining.

Return type:

HyperparameterSpaceBuilder