code: def _create_custom_metric_flaml(
      task: str,
      metric_name: str,
      coeff: int,
      eval_metric: EvaluationMetric,
  ) -> callable:
      def calc_metric(X, y, estimator) -> Dict[str, float]:
          y_pred = estimator.predict(X)
          builtin_metrics = (
              _get_regressor_metrics(y, y_pred, sample_weights=None)
              if task == "regression"
              else _get_binary_classifier_metrics(
                  y_true=y, y_pred=y_pred
              )
          )
          res_df = pd.DataFrame()
          res_df["prediction"] = y_pred
          res_df["target"] = y if task == "classification" else y.values
          return eval_metric.eval_fn(res_df, builtin_metrics)
  
      # pylint: disable=keyword-arg-before-vararg
      # pylint: disable=unused-argument
      def custom_metric(
          X_val,
          y_val,
          estimator,
          labels,
          X_train,
          y_train,
          weight_val=None,
          weight_train=None,
          *args,
      ):
          val_metric = coeff * calc_metric(X_val, y_val, estimator)
          train_metric = calc_metric(X_train, y_train, estimator)
          main_metric = coeff * val_metric
          return main_metric, {
              f"{metric_name}_train": train_metric,
              f"{metric_name}_val": val_metric,
          }
  
      return custom_metric
  
file_path: mlflow/mlflow/recipes/steps/automl/flaml.py
imports: import importlib
  import logging
  from typing import TYPE_CHECKING, Any, Dict, Tuple
  import pandas
  import mlflow
  from mlflow import MlflowException
  from mlflow.models import EvaluationMetric
  from mlflow.models.evaluation.default_evaluator import _get_binary_classifier_metrics, _get_regressor_metrics
  from mlflow.recipes.utils.metrics import RecipeMetric, _load_custom_metrics
label_desc: Use image node_id 2 for calling a global function with example usage: _create_custom_metric_flaml(task, metric_name, coeff, eval_metric) and returns: custom_metric, eval_metric, main_metric,  dict