class_docstr: Test random hyperparameter optimization API.
class_docstr_tok: ["Test","random","hyperparameter","optimization","API","."]
docstr: Test that using a logdir can work correctly.
docstr_tok: ["Test","that","using","a","logdir","can","work","correctly","."]
code: def test_rf_with_logdir(self):
      """Test that using a logdir can work correctly."""
      optimizer = dc.hyper.RandomHyperparamOpt(
          self.rf_model_builder, max_iter=self.max_iter
      )
      sampler = uniform(loc=0, scale=0.001).rvs
      params_dict = {
          "n_estimators": [10, 5],
          "min_impurity_decrease": sampler,
      }
      transformers = []
      metric = dc.metrics.Metric(dc.metrics.pearson_r2_score)
  
      with tempfile.TemporaryDirectory() as tmpdirname:
          (
              best_model,
              best_hyperparams,
              all_results,
          ) = optimizer.hyperparam_search(
              params_dict,
              self.train_dataset,
              self.valid_dataset,
              metric,
              transformers,
              logdir=tmpdirname,
          )
          # max_iter model variants, 1 results.txt file
          assert len(os.listdir(tmpdirname)) == self.max_iter + 1
  
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 4 for calling the TestRandomHyperparamOpt obj's underlying member method code with example usage: obj.test_rf_with_logdir() without return types