class_docstr: Test random hyperparameter optimization API.
class_docstr_tok: ["Test","random","hyperparameter","optimization","API","."]
docstr: Test a simple example of optimizing a multitask model with a random search.
docstr_tok: ["Test","a","simple","example","of","optimizing","a","multitask","model","with","a","random","search","."]
code: def test_multitask_example(self):
      """Test a simple example of optimizing a multitask model with a random search."""
      # Generate dummy dataset
      np.random.seed(123)
      train_dataset = dc.data.NumpyDataset(
          np.random.rand(10, 3),
          np.zeros((10, 2)),
          np.ones((10, 2)),
          np.arange(10),
      )
      valid_dataset = dc.data.NumpyDataset(
          np.random.rand(5, 3),
          np.zeros((5, 2)),
          np.ones((5, 2)),
          np.arange(5),
      )
  
      optimizer = dc.hyper.RandomHyperparamOpt(
          lambda **params: dc.models.MultitaskRegressor(
              n_tasks=2,
              n_features=3,
              dropouts=[0.0],
              weight_init_stddevs=[np.sqrt(6) / np.sqrt(1000)],
              learning_rate=0.003,
              **params,
          ),
          max_iter=self.max_iter,
      )
  
      params_dict = {"batch_size": [10, 20]}
      transformers = []
      metric = dc.metrics.Metric(
          dc.metrics.mean_squared_error, task_averager=np.mean
      )
      (
          best_model,
          best_hyperparams,
          all_results,
      ) = optimizer.hyperparam_search(
          params_dict,
          train_dataset,
          valid_dataset,
          metric,
          transformers,
          use_max=False,
      )
  
      valid_score = best_model.evaluate(valid_dataset, [metric])
      assert valid_score["mean-mean_squared_error"] == min(
          all_results.values()
      )
      assert valid_score["mean-mean_squared_error"] > 0
  
file_path: deepchem/deepchem/hyper/tests/test_random_hyperparam_opt.py
imports: import unittest
  import tempfile
  import numpy
  import pytest
  import deepchem
  import sklearn
  import sklearn.ensemble
  import os
  from scipy.stats import uniform
label_desc: Use image node_id 5 for calling the TestRandomHyperparamOpt obj's underlying member method code with example usage: obj.test_multitask_example() without return types