HyperparameterSpace#

This class provides a way to define search spaces for hyperparameters.

class mloptimizer.domain.hyperspace.HyperparameterSpace(fixed_hyperparams: dict, evolvable_hyperparams: dict)[source]#

Bases: object

This class represents the hyperparameter space for a scikit-learn classifier. It contains the fixed hyperparameters and the evolvable hyperparameters. The fixed hyperparameters are just a dictionary with the hyperparameters that are not going to be optimized and their value. The evolvable hyperparameters are a dictionary with the hyperparameters that are going to be optimized. The keys are the hyperparameter names and the values are instances of the Hyperparam class.

fixed_hyperparams#

Dictionary with the fixed hyperparameters

Type:

dict

evolvable_hyperparams#

Dictionary with the evolvable hyperparameters of Hyperparam instances

Type:

dict

Constructs all the necessary attributes for the HyperparameterSpace object.

Parameters:
  • fixed_hyperparams (dict) – Dictionary with the fixed hyperparameters

  • evolvable_hyperparams (dict) – Dictionary with the evolvable hyperparameters of Hyperparam instances

default_hyperparameter_spaces_json = '/home/docs/checkouts/readthedocs.org/user_builds/mloptimizer/checkouts/master/mloptimizer/domain/hyperspace/../../infrastructure/config/hyperspace/default_hyperparameter_spaces.json'#
classmethod from_json(file_path)[source]#

This method creates a HyperparameterSpace object from a JSON file.

Parameters:

file_path (str) – Path to the JSON file

Return type:

HyperparameterSpace

Raises:
classmethod from_json_data(json_data)[source]#

Create a HyperparameterSpace object from a dictionary (JSON data).

Parameters:

json_data (dict) – Dictionary containing the hyperparameter space data.

Returns:

An instance of HyperparameterSpace.

Return type:

HyperparameterSpace

get_all_params()[source]#

This method returns a dictionary with all the hyperparameters, fixed and evolvable.

Returns:

Dictionary with all the hyperparameters

Return type:

dict

static get_default_hyperparameter_space(estimator_class)[source]#

This method returns a dictionary with the default hyperparameters for the scikit-learn classifier. It reads the default_hyperparameter_spaces.json file and returns the hyperparameters for the classifier

Parameters:

estimator_class (class) – The scikit-learn classifier class

Returns:

The hyperparameter space for the classifier

Return type:

HyperparameterSpace

to_json(file_path, overwrite=False)[source]#

This method saves the hyperparameter space as a JSON file.

Parameters:
  • file_path (str) – Path to the JSON file

  • overwrite (bool, optional (default=False)) – If True, the file will be overwritten if it exists. If False, a FileExistsError will be raised if the file exists

Raises: