class_docstr: Provides simple random hyperparameter search capabilities.
  
  This class performs a random hyperparameter search over the specified
  hyperparameter space. This implementation is simple and samples
  hyperparameters from the hyperparameter space passed. However it does not
  use parallelization to speed up the search.
  
  Examples
  --------
  This example shows the type of constructor function expects.
  
  >>> import sklearn
  >>> import deepchem as dc
  >>> optimizer = dc.hyper.RandomHyperparamOpt(lambda **p: dc.models.GraphConvModel(**p), max_iter=5)
  
  Here's a more sophisticated example that shows how to optimize only
  some parameters of a model. In this case, we have some parameters we
  want to optimize, and others which we don't. To handle this type of
  search, we create a `model_builder` which hard codes some arguments.
  
  >>> import deepchem as dc
  >>> import numpy as np
  >>> from sklearn.linear_model import LogisticRegression as LR
  >>> # generating data
  >>> X = np.arange(1, 11, 1).reshape(-1, 1)
  >>> y = np.hstack((np.zeros(5), np.ones(5)))
  >>> dataset = dc.data.NumpyDataset(X, y)
  >>> # splitting dataset into train and test
  >>> splitter = dc.splits.RandomSplitter()
  >>> train_dataset, test_dataset = splitter.train_test_split(dataset)
  >>> # metric to evaluate result of a set of parameters
  >>> metric = dc.metrics.Metric(dc.metrics.accuracy_score)
  >>> # defining `model_builder`
  >>> def model_builder(**model_params):
  ...   penalty = model_params['penalty']
  ...   solver = model_params['solver']
  ...   lr = LR(penalty=penalty, solver=solver, max_iter=100)
  ...   return dc.models.SklearnModel(lr)
  >>> # the parameters which are to be optimized
  >>> params = {
  ...   'penalty': ['l1', 'l2'],
  ...   'solver': ['liblinear', 'saga']
  ...   }
  >>> # Creating optimizer and searching over hyperparameters
  >>> optimizer = dc.hyper.RandomHyperparamOpt(model_builder, max_iter=100)
  >>> best_model, best_hyperparams, all_results = optimizer.hyperparam_search(params, train_dataset, test_dataset, metric)
  >>> best_hyperparams['penalty'], best_hyperparams['solver']  # doctest: +SKIP
  ('l2', 'saga')
  
  Parameters
  ----------
  model_builder: constructor function.
      This parameter must be constructor function which returns an
      object which is an instance of `dc.models.Model`. This function
      must accept two arguments, `model_params` of type `dict` and
      `model_dir`, a string specifying a path to a model directory.
  max_iter: int
      Maximum number of iterations to perform
class_docstr_tok: ["Provides","simple","random","hyperparameter","search","capabilities",".","This","class","performs","a","random","hyperparameter","search","over","the","specified","hyperparameter","space",".","This","implementation","is","simple","and","samples","hyperparameters","from","the","hyperparameter","space","passed",".","However","it","does","not","use","parallelization","to","speed","up","the","search",".","Examples","--","--","--","--","This","example","shows","the","type","of","constructor","function","expects",".",">",">",">","import","sklearn",">",">",">","import","deepchem","as","dc",">",">",">","optimizer","=","dc.hyper.RandomHyperparamOpt","(","lambda","*","*","p",":","dc.models.GraphConvModel","(","*","*","p",")",",","max_iter=5",")","Here","'s","a","more","sophisticated","example","that","shows","how","to","optimize","only","some","parameters","of","a","model",".","In","this","case",",","we","have","some","parameters","we","want","to","optimize",",","and","others","which","we","do","n't",".","To","handle","this","type","of","search",",","we","create","a","`","model_builder","`","which","hard","codes","some","arguments",".",">",">",">","import","deepchem","as","dc",">",">",">","import","numpy","as","np",">",">",">","from","sklearn.linear_model","import","LogisticRegression","as","LR",">",">",">","#","generating","data",">",">",">","X","=","np.arange","(","1",",","11",",","1",")",".reshape","(","-1",",","1",")",">",">",">","y","=","np.hstack","(","(","np.zeros","(","5",")",",","np.ones","(","5",")",")",")",">",">",">","dataset","=","dc.data.NumpyDataset","(","X",",","y",")",">",">",">","#","splitting","dataset","into","train","and","test",">",">",">","splitter","=","dc.splits.RandomSplitter","(",")",">",">",">","train_dataset",",","test_dataset","=","splitter.train_test_split","(","dataset",")",">",">",">","#","metric","to","evaluate","result","of","a","set","of","parameters",">",">",">","metric","=","dc.metrics.Metric","(","dc.metrics.accuracy_score",")",">",">",">","#","defining","`","model_builder","`",">",">",">","def","model_builder","(","*","*","model_params",")",":","...","penalty","=","model_params","[","'penalty","'","]","...","solver","=","model_params","[","'solver","'","]","...","lr","=","LR","(","penalty=penalty",",","solver=solver",",","max_iter=100",")","...","return","dc.models.SklearnModel","(","lr",")",">",">",">","#","the","parameters","which","are","to","be","optimized",">",">",">","params","=","{","...","'penalty","'",":","[","'l1","'",",","'l2","'","]",",","...","'solver","'",":","[","'liblinear","'",",","'saga","'","]","...","}",">",">",">","#","Creating","optimizer","and","searching","over","hyperparameters",">",">",">","optimizer","=","dc.hyper.RandomHyperparamOpt","(","model_builder",",","max_iter=100",")",">",">",">","best_model",",","best_hyperparams",",","all_results","=","optimizer.hyperparam_search","(","params",",","train_dataset",",","test_dataset",",","metric",")",">",">",">","best_hyperparams","[","'penalty","'","]",",","best_hyperparams","[","'solver","'","]","#","doctest",":","+SKIP","(","'l2","'",",","'saga","'",")","Parameters","--","--","--","--","--","model_builder",":","constructor","function",".","This","parameter","must","be","constructor","function","which","returns","an","object","which","is","an","instance","of","`","dc.models.Model","`",".","This","function","must","accept","two","arguments",",","`","model_params","`","of","type","`","dict","`","and","`","model_dir","`",",","a","string","specifying","a","path","to","a","model","directory",".","max_iter",":","int","Maximum","number","of","iterations","to","perform"]
code: def __init__(
      self, model_builder: Callable[..., Model], max_iter: int
  ):
      super(RandomHyperparamOpt, self).__init__(
          model_builder=model_builder
      )
      self.max_iter = max_iter
  
file_path: deepchem/deepchem/hyper/random_search.py
imports: import numpy
  import os
  import tempfile
  import collections
  import logging
  import itertools
  from typing import Dict, List, Optional, Tuple, Any, Callable
  from deepchem.data import Dataset
  from deepchem.trans import Transformer
  from deepchem.models import Model
  from deepchem.metrics import Metric
  from deepchem.hyper.base_classes import HyperparamOpt
  from deepchem.hyper.base_classes import _convert_hyperparam_dict_to_filename
label_desc: Use image node_id 1 to create a new RandomHyperparamOpt object from inherited base classes: HyperparamOpt with example: obj = RandomHyperparamOpt(model_builder, max_iter)