utils.tuning package
Submodules
utils.tuning.hyper_grid_search module
- class utils.tuning.hyper_grid_search.HyperGridSearch(**kwargs)
Bases:
HyperTuner- Author:
Alberto M. Esmoris Pena
Class to apply grid search on the hyperparameter space of a model.
- Variables:
nthreads (int) – Number of threads to run parallel grid search nodes. Note that the model might have nthreads too. In this case, it is important that the number of threads from the grid search and the number of threads from the model itself are considered together.
num_folds (int) – Number of folds to train and validate the model on a kfolding scheme for each node in the grid search.
pre_dispatch (int or str) – How many jobs are dispatched during the parallel execution. It can be useful to prevent dispatching more jobs than those that can be processed by the CPUs.
grid (dict) – Dictionary which elements are lists. Each list in the dictionary represents the values that must be searched for the parameter referenced by the key.
- static extract_tuner_args(spec)
Extract the arguments to initialize/instantiate an HyperGridSearch from a key-word specification.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate an HyperGridSearch.
- __init__(**kwargs)
Initialize/instantiate an HyperGridSearch.
- Parameters:
kwargs – The attributes for the HyperGridSearch
- tune(model, pcloud=None)
Tune the given model with the best configuration found after computing a grid search on the model’s hyperparameters space. See
HyperTunerandTuner. Also, seetuner.Tuner.tune()- Parameters:
model – The model which hyperparameters must be tuned.
pcloud – The input point cloud (cannot be None).
utils.tuning.hyper_random_search module
- class utils.tuning.hyper_random_search.HyperRandomSearch(**kwargs)
Bases:
HyperTuner- Author:
Alberto M. Esmoris Pena
Class to apply random search on the hyperparameter space of a model.
- Variables:
nthreads (int) – Number of threads to run parallel grid search nodes. Note that the model might have nthreads too. In this case, it is important that the number of threads from the grid search and the number of threads from the model itself are considered together.
num_folds (int) – Number of folds to train and validate the model on a kfolding scheme for each node in the grid search.
iterations (int) – The number of iterations. Each iteration will randomly select values from the random distributions to test a model.
distributions (dict) – Dictionary which elements are dictionaries that define a particular distribution to generate random values for a concrete hyperparameter.
pre_dispatch (int or str) – How many jobs are dispatched during the parallel execution. It can be useful to prevent dispatching more jobs than those that can be processed by the CPUs.
- static extract_tuner_args(spec)
Extract the arguments to initialize/instantiate an HyperRandomSearch from a key-word specification.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate an HyperRandomSearch.
- __init__(**kwargs)
Initialize/instantiate an HyperRandomSearch.
- Parameters:
kwargs – The attributes for the HyperRandomSearch
- tune(model, pcloud=None)
Tune the given model with the best configuration found after computing a random search on the model’s hyperparameters space. See
HyperTunerandTuner. Also, seetuner.Tuner.tune()- Parameters:
model – The model which hyperparameters must be tuned.
pcloud – The input point cloud (cannot be None)
- static build_distributions(distributions)
Transform the specified distributions instantiating the corresponding objects to represent random distributions.
- Parameters:
distributions – The specification of the distributions.
- Returns:
The built distributions.
utils.tuning.hyper_tuner module
- class utils.tuning.hyper_tuner.HyperTuner(**kwargs)
Bases:
Tuner,ABC- Author:
Alberto M. Esmoris Pena
Class for model’s hyperparameters tuning.
- Variables:
report_path (str) – The path (OPTIONAL) to export the hyperparameter tuning report.
hpnames (list or tuple or np.ndarray) – The names (as strings) of the hyperparameters to be considered.
scores (str or list or dict or tuple or callable or None) – The scores that must be optimized during hyperparameter tuning (None means using the default behavior for each hyper tuner).
- static extract_tuner_args(spec)
Extract the arguments to initialize/instantiate an HyperTuner from a key-word specification.
- Parameters:
spec – The key-word specification containing the arguments.
- Returns:
The arguments to initialize/instantiate an HyperTuner.
- __init__(**kwargs)
Initialize/instantiate an HyperTuner.
- Parameters:
kwargs – The attributes for the HyperTuner.
- static search(model, search, pcloud)
Compute the search of the best hyperparameters for the given model on the given point cloud.
- Parameters:
model – The model which hyperparameters must be tuned. See
Model.search – The search object (must have a fit method to be applied on a features matrix and a vector of classes, i.e., F and y).
pcloud – The point cloud representing the input data for the search.
- Returns:
Completed search.
- static update_model(model, search, pcloud=None)
Update model from result.
- static update_model_with_no_refit(model, search, pcloud=None)
Compute the model update when the hyperparameter tuning ends without refitting the model. See
HyperTuner.update_model().
- static update_model_from_refit(model, search, pcloud=None)
Compute the model update when the hyperparameter tuning refits the model after finishing. See
HyperTuner.update_model().
- static kwargs_hyperparameters_from_spec(kwargs, spec)
Update the key-word arguments (kwargs) to derive the hyperparameters from the specification. In case there are explicitly given hyperparameters, they must match exactly with the specification.
- Parameters:
kwargs – The key-word arguments to be updated.
spec – The specification, often a dictionary contained inside the key-word arguments.
- Returns:
The updated key-word arguments.
utils.tuning.tuner module
- exception utils.tuning.tuner.TunerException(message='')
Bases:
VL3DException- Author:
Alberto M. Esmoris Pena
Class for exceptions related to tuning components. See
VL3DException- __init__(message='')
- class utils.tuning.tuner.Tuner(**kwargs)
Bases:
object- Author:
Alberto M. Esmoris Pena
Class for model tuning operations.
- __init__(**kwargs)
Initialize/instantiate a Tuner.
- Parameters:
kwargs – The attributes for the Tuner.
- abstractmethod tune(model, pcloud=None)
Tune the given model on givel point cloud (if any).
- Parameters:
model – The model to be tuned. See
Modelpcloud – The point cloud involved in the tuning. See
PointCloud
- Returns:
The tuned model.
- Return type:
Module contents
- author:
Alberto M. Esmoris Pena
The tuning package contains the logic to tune models, e.g., hyperparameter tuning through grid search.