code: def _get_best_value_and_best_epoch_from_history(history, objective):
      # A dictionary to record the metric values through epochs.
      # Usage: epoch_metric[epoch_number][metric_name] == metric_value
      epoch_metrics = collections.defaultdict(dict)
      for metric_name, epoch_values in history.history.items():
          for epoch, value in enumerate(epoch_values):
              epoch_metrics[epoch][metric_name] = value
      best_epoch = 0
      for epoch, metrics in epoch_metrics.items():
          objective_value = objective.get_value(metrics)
          # Support multi-objective.
          if objective.name not in metrics:
              metrics[objective.name] = objective_value
          best_value = epoch_metrics[best_epoch][objective.name]
          if objective.better_than(objective_value, best_value):
              best_epoch = epoch
      return epoch_metrics[best_epoch], best_epoch
  
imports: import collections
  import statistics
  import numpy
  from keras_tuner import backend
  from keras_tuner import errors
  from keras_tuner.backend import config
  from keras_tuner.backend import keras
  from keras_tuner.engine import hyperparameters
  from keras_tuner.engine import objective
label_desc: Use image node_id 2 for calling a global function with example usage: _get_best_value_and_best_epoch_from_history(history, objective) and returns: epoch_metrics,  best_epoch