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: object

Base class for hyperparameter search with cross-validation for DeepChemModels.

fit(dataset: Dataset)[source]

Run hyperparameter search with cross-validation.

Parameters

dataset (Dataset) – The dataset to use for the hyperparameter search.

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: DeepchemBaseSearchCV

Hyperparameter 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: DeepchemBaseSearchCV

Hyperparameter 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: object

Abstract superclass for hyperparameter search classes.

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: HyperparameterOptimizer

Provides simple grid hyperparameter search capabilities. This class performs a grid hyperparameter search over the specified hyperparameter space.

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: HyperparameterOptimizer

Provides simple grid hyperparameter search capabilities. This class performs a grid hyperparameter search over the specified hyperparameter space.

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]]

Module contents