deepmol.parameter_optimization package
Submodules
deepmol.parameter_optimization.deepchem_hyperparameter_optimization module
Hyperparameter Optimization Classes for DeepchemModel models
- class DeepchemBaseSearchCV(model_build_fn: callable, param_grid: Union[dict, ParameterGrid, ParameterSampler], scoring: Union[Metric, List[Metric]], maximize: bool, refit: bool, cv: int, mode: str, random_state: Optional[int] = None, return_train_score: bool = False)[source]
Bases:
objectBase class for hyperparameter search with cross-validation for DeepChemModels.
- class DeepchemGridSearchCV(model_build_fn: callable, param_grid: Union[dict, ParameterGrid], scoring: Union[Metric, List[Metric]], maximize: bool, refit: bool, cv: int, mode: str, random_state: Optional[int] = None, return_train_score: bool = False)[source]
Bases:
DeepchemBaseSearchCVHyperparameter search with cross-validation for DeepChemModels using a grid search.
- class DeepchemRandomSearchCV(model_build_fn: callable, param_distributions: Union[dict, ParameterSampler], scoring: Union[Metric, List[Metric]], maximize: bool, refit: bool, cv: int, mode: str, random_state: Optional[int] = None, return_train_score: bool = False, n_iter: int = 20)[source]
Bases:
DeepchemBaseSearchCVHyperparameter search with cross-validation for DeepChemModels using a random search.
deepmol.parameter_optimization.hyperparameter_optimization module
- class HyperparameterOptimizer(model_builder: callable, mode: Optional[str] = None)[source]
Bases:
objectAbstract superclass for hyperparameter search classes.
- abstract hyperparameter_search(params_dict: Dict[str, Any], train_dataset: Dataset, valid_dataset: Dataset, metric: Metric, maximize_metric: bool, logdir: Optional[str] = None, **kwargs) Tuple[Model, Dict[str, Any], Dict[str, float]][source]
Conduct Hyperparameter search.
This method defines the common API shared by all hyperparameter optimization subclasses. Different classes will implement different search methods, but they must all follow this common API.
- Parameters
params_dict (Dict) – Dictionary mapping strings to values. Note that the precise semantics of params_dict will change depending on the optimizer that you’re using.
train_dataset (Dataset) – The training dataset.
valid_dataset (Dataset) – The validation dataset.
metric (Metric) – The metric to optimize.
maximize_metric (bool) – If True, return the model with the highest score.
logdir (str) – The directory in which to store created models. If not set, will use a temporary directory.
**kwargs (Dict) – Additional keyword arguments to pass to the model constructor.
- Returns
A tuple containing the best model, the best hyperparameters, and all scores.
- Return type
Tuple[Model, Dict[str, Any], Dict[str, float]]
- class HyperparameterOptimizerCV(model_builder: callable, mode: Optional[str] = None)[source]
Bases:
HyperparameterOptimizerProvides simple grid hyperparameter search capabilities. This class performs a grid hyperparameter search over the specified hyperparameter space.
- hyperparameter_search(model_type: str, params_dict: Dict, train_dataset: Dataset, metric: Union[Metric, List[Metric]], maximize_metric: bool = True, cv: int = 3, n_iter_search: int = 15, n_jobs: int = 1, verbose: int = 0, logdir: Optional[str] = None, seed: Optional[int] = None, refit: bool = True, **kwargs) Tuple[Model, Dict, Dict][source]
Perform hyperparams search according to params_dict. Each key to hyperparams_dict is a model_param. The values should be a list of potential values for that hyperparameter.
- Parameters
model_type (str) – Type of model to use. Must be one of ‘sklearn’, ‘keras’, and ‘deepchem’.
params_dict (Dict) – Dictionary mapping hyperparameter names (strings) to lists of possible parameter values.
train_dataset (Dataset) – Dataset to train on.
metric (Union[Metric, List[Metric]]) – Metric or metrics to optimize over.
maximize_metric (bool) – Whether to maximize or minimize the metric.
cv (int) – Number of cross-validation folds to perform.
n_iter_search (int) – Number of hyperparameter combinations to try.
n_jobs (int) – Number of jobs to run in parallel.
verbose (int) – Verbosity level.
logdir (str) – The directory in which to store created models. If not set, will use a temporary directory.
seed (int) – Random seed to use.
refit (bool) – Whether to refit the best model on the entire training set.
kwargs (dict) – Additional keyword arguments to pass to the model constructor.
- Returns
A tuple containing the best model, the best hyperparameters, and all scores.
- Return type
Tuple[Model, Dict[str, Any], Dict[str, float]]
- class HyperparameterOptimizerValidation(model_builder: callable, mode: Optional[str] = None)[source]
Bases:
HyperparameterOptimizerProvides simple grid hyperparameter search capabilities. This class performs a grid hyperparameter search over the specified hyperparameter space.
- hyperparameter_search(params_dict: Dict, train_dataset: Dataset, valid_dataset: Dataset, metric: Metric, maximize_metric: bool, n_iter_search: int = 15, n_jobs: int = 1, verbose: int = 0, logdir: Optional[str] = None, **kwargs)[source]
Perform hyperparams search according to params_dict. Each key to hyperparams_dict is a model_param. The values should be a list of potential values for that hyperparameter.
- Parameters
params_dict (Dict) – Dictionary mapping hyperparameter names (strings) to lists of possible parameter values.
train_dataset (Dataset) – The training dataset.
valid_dataset (Dataset) – The validation dataset.
metric (Metric) – The metric to optimize.
maximize_metric (bool) – If True, return the model with the highest score.
n_iter_search (int) – Number of random combinations of parameters to test, if None performs complete grid search.
n_jobs (int) – Number of jobs to run in parallel.
verbose (int) – Controls the verbosity: the higher, the more messages.
logdir (str) – The directory in which to store created models. If not set, will use a temporary directory.
- Returns
A tuple containing the best model, the best hyperparameters, and all scores.
- Return type
Tuple[Model, Dict[str, Any], Dict[str, float]]