mloptimizer.hyperparams
#
Submodules#
Package Contents#
Classes#
Class to define a hyperparam to optimize. It defines the name, min value, max value and type. |
|
This class represents the hyperparameter space for a scikit-learn classifier. It contains the fixed hyperparameters |
- class mloptimizer.hyperparams.Hyperparam(name: str, min_value: int, max_value: int, hyperparam_type: str, scale: int = 100, values_str: list = None)[source]#
Bases:
object
Class to define a hyperparam to optimize. It defines the name, min value, max value and type. This is used to control the precision of the hyperparam and avoid multiple evaluations with close values of the hyperparam due to decimal positions.
- name#
Name of the hyperparam. It will be used as key in a dictionary
- Type:
str
- min_value#
Minimum value of the hyperparam
- Type:
int
- max_value#
Maximum value of the hyperparam
- Type:
int
- hyperparam_type#
Type of the hyperparam (‘int’, ‘float’, ‘nexp’, ‘x10’)
- Type:
str
- scale#
Optional param in case the type=float
- Type:
int, optional (default=100)
- values_str#
List of string with possible values (TODO)
- Type:
list, optional (default=[])
- class mloptimizer.hyperparams.HyperparameterSpace(fixed_hyperparams: dict, evolvable_hyperparams: dict)[source]#
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
- 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:
- Raises:
FileNotFoundError – If the file does not exist
json.JSONDecodeError – If the file is not a valid JSON file
- 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:
ValueError – If the file path is None
FileExistsError – If the file exists and overwrite is False
- 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: