code: def func_generator(
      metric, is_higher_better, needs_pred_proba, problem_type
  ):
      if needs_pred_proba:
          if problem_type == MULTICLASS:
  
              def function_template(y_hat, data):
                  y_true = data.get_label()
                  y_hat = y_hat.reshape(len(np.unique(y_true)), -1).T
                  return (
                      metric.name,
                      metric(y_true, y_hat),
                      is_higher_better,
                  )
  
          elif (
              problem_type == SOFTCLASS
          ):  # metric must take in soft labels array, like soft_log_loss
  
              def function_template(y_hat, data):
                  y_true = data.softlabels
                  y_hat = y_hat.reshape(y_true.shape[1], -1).T
                  y_hat = np.exp(y_hat)
                  y_hat = np.multiply(
                      y_hat, 1 / np.sum(y_hat, axis=1)[:, np.newaxis]
                  )
                  return (
                      metric.name,
                      metric(y_true, y_hat),
                      is_higher_better,
                  )
  
          else:
  
              def function_template(y_hat, data):
                  y_true = data.get_label()
                  return (
                      metric.name,
                      metric(y_true, y_hat),
                      is_higher_better,
                  )
  
      else:
          if problem_type == MULTICLASS:
  
              def function_template(y_hat, data):
                  y_true = data.get_label()
                  y_hat = y_hat.reshape(len(np.unique(y_true)), -1)
                  y_hat = y_hat.argmax(axis=0)
                  return (
                      metric.name,
                      metric(y_true, y_hat),
                      is_higher_better,
                  )
  
          else:
  
              def function_template(y_hat, data):
                  y_true = data.get_label()
                  y_hat = np.round(y_hat)
                  return (
                      metric.name,
                      metric(y_true, y_hat),
                      is_higher_better,
                  )
  
      return function_template
  
imports: import copy
  import os
  import time
  from typing import List, Optional
  import numpy
  import pandas
  from pandas import DataFrame, Series
  from autogluon.common.utils.try_import import try_import_lightgbm
  from autogluon.core.constants import BINARY, MULTICLASS, QUANTILE, REGRESSION, SOFTCLASS
  from autogluon.core.utils.exceptions import TimeLimitExceeded
label_desc: Use image node_id 2 for calling a global function with example usage: func_generator(metric, is_higher_better, needs_pred_proba, problem_type) and returns: function_template, metric,  metric,  is_higher_better, metric,  metric,  is_higher_better, metric,  metric,  is_higher_better, metric,  metric,  is_higher_better, metric,  metric,  is_higher_better