class_docstr: This class is created to test the three stopping conditions for randomized gridsearch using
  GLM Binomial family.  The three stopping conditions are :
  
  1. max_runtime_secs:
  2. max_models:
  3. metrics.  We will be picking 2 stopping metrics to test this stopping condition with.  One metric
  will be optimized if it increases and the other one should be optimized if it decreases.
  
  I have written 4 tests:
  1. test1_glm_random_grid_search_model_number: this test will not put any stopping conditions
  on randomized search.  The purpose here is to make sure that randomized search will give us all possible
  hyper-parameter combinations.
  2. test2_glm_random_grid_search_max_model: this test the stopping condition of setting the max_model in
  search criteria;
  3. test3_glm_random_grid_search_max_runtime_secs: this test the stopping condition max_runtime_secs
  in search criteria;
  4. test4_glm_random_grid_search_metric: this test the stopping condition of using a metric which can be
  increasing or decreasing.
class_docstr_tok: ["This","class","is","created","to","test","the","three","stopping","conditions","for","randomized","gridsearch","using","GLM","Binomial","family",".","The","three","stopping","conditions","are",":","1.","max_runtime_secs",":","2.","max_models",":","3.","metrics",".","We","will","be","picking","2","stopping","metrics","to","test","this","stopping","condition","with",".","One","metric","will","be","optimized","if","it","increases","and","the","other","one","should","be","optimized","if","it","decreases",".","I","have","written","4","tests",":","1.","test1_glm_random_grid_search_model_number",":","this","test","will","not","put","any","stopping","conditions","on","randomized","search",".","The","purpose","here","is","to","make","sure","that","randomized","search","will","give","us","all","possible","hyper-parameter","combinations",".","2.","test2_glm_random_grid_search_max_model",":","this","test","the","stopping","condition","of","setting","the","max_model","in","search","criteria",";","3.","test3_glm_random_grid_search_max_runtime_secs",":","this","test","the","stopping","condition","max_runtime_secs","in","search","criteria",";","4.","test4_glm_random_grid_search_metric",":","this","test","the","stopping","condition","of","using","a","metric","which","can","be","increasing","or","decreasing","."]
docstr: This function will test the last stopping condition using metrics.
  
  :param metric_name: metric we want to use to test the last stopping condition
  :param bigger_is_better: higher metric value indicates better model performance
  
  :return: None
docstr_tok: ["This","function","will","test","the","last","stopping","condition","using","metrics",".",":","param","metric_name",":","metric","we","want","to","use","to","test","the","last","stopping","condition",":","param","bigger_is_better",":","higher","metric","value","indicates","better","model","performance",":","return",":","None"]
code: def test4_glm_random_grid_search_metric(
      self, metric_name, bigger_is_better
  ):
      """
      This function will test the last stopping condition using metrics.
  
      :param metric_name: metric we want to use to test the last stopping condition
      :param bigger_is_better: higher metric value indicates better model performance
  
      :return: None
      """
      print(
          "*******************************************************************************************"
      )
      print(
          "test4_glm_random_grid_search_metric using "
          + metric_name
          + " for family "
          + self.family
      )
      h2o.cluster_info()
  
      search_criteria = {
          "strategy": "RandomDiscrete",
          "stopping_metric": metric_name,
          "stopping_tolerance": random.uniform(
              1e-8, self.max_tolerance
          ),
          "stopping_rounds": random.randint(
              1, self.max_stopping_rounds
          ),
          "seed": round(time.time()),
      }
  
      print(
          "GLM Gaussian grid search_criteria: {0}".format(
              search_criteria
          )
      )
  
      # add max_runtime_secs back into hyper-parameters to limit model runtime.
      self.hyper_params["max_runtime_secs"] = [
          0.3
      ]  # arbitrarily set to 0.1 second
  
      # fire off random grid-search
      grid_model = H2OGridSearch(
          H2OGeneralizedLinearEstimator(
              family=self.family, nfolds=self.nfolds
          ),
          hyper_params=self.hyper_params,
          search_criteria=search_criteria,
      )
      grid_model.train(
          x=self.x_indices,
          y=self.y_index,
          training_frame=self.training1_data,
      )
  
      # bool indicating if randomized grid search has calculated the early stopping condition correctly
      stopped_correctly = pyunit_utils.evaluate_metrics_stopping(
          grid_model.models,
          metric_name,
          bigger_is_better,
          search_criteria,
          self.possible_number_models,
      )
  
      if stopped_correctly:
          print(
              "test4_glm_random_grid_search_metric "
              + metric_name
              + ": passed. "
          )
      else:
          self.test_failed += 1
          self.test_failed_array[self.test_num] = 1
          print(
              "test4_glm_random_grid_search_metric "
              + metric_name
              + ": failed. "
          )
  
      self.test_num += 1
  
file_path: h2o-3/h2o-py/dynamic_tests/testdir_algos/glm/pyunit_glm_gaussian_gridsearch_randomdiscrete_large.py
imports: import sys
  import random
  import os
  from builtins import range
  import time
  import json
  import h2o
  from tests import pyunit_utils
  from h2o.estimators.glm import H2OGeneralizedLinearEstimator
  from h2o.grid.grid_search import H2OGridSearch
label_desc: Use image node_id 8 for calling the Test_glm_random_grid_search obj's underlying member method code with example usage: obj.test4_glm_random_grid_search_metric(metric_name, bigger_is_better) without return types