code: def make_derived_metric(
      *,
      metric: Callable[..., Union[float, int]],
      transform: str,
      sample_param_names: List[str] = ["sample_weight"],
  ) -> Callable[..., Union[float, int]]:
      """Create a scalar returning metric function based on aggregation of a disaggregated metric.
  
      Many higher order machine learning operations (such as hyperparameter tuning)
      make use of functions which return scalar metrics. We can create such a function
      for our disaggregated metrics with this function.
  
      This function takes a metric function, a string to specify the desired aggregation
      transform (matching the methods :meth:`MetricFrame.group_min`,
      :meth:`MetricFrame.group_max`, :meth:`MetricFrame.difference` and
      :meth:`MetricFrame.ratio`), and a list of
      parameter names to treat as sample parameters.
  
      The result is a callable object which has the same signature as the original
      function, with a :code:`sensitive_features=` parameter added.
      If the chosen aggregation transform accepts parameters (currently only
      :code:`method=` is supported), these can also be given when invoking the
      callable object.
      The result of this function is identical to
      creating a :class:`MetricFrame` object, and then calling the method specified
      by the :code:`transform=` argument (with the :code:`method=` argument, if
      required).
  
      See the :ref:`custom_fairness_metrics` section in the :ref:`user_guide` for more
      details.
      A :ref:`sample notebook <sphx_glr_auto_examples_plot_make_derived_metric.py>` is
      also available.
  
      Parameters
      ----------
      metric : callable
          The metric function from which the new function should be derived
  
      transform : str
          Selects the transformation aggregation the resultant function should use.
          The list of possible options is:
          ['difference', 'group_min', 'group_max', 'ratio'].
  
      sample_param_names : List[str]
          A list of parameters names of the underlying :code:`metric` which should
          be treated as sample parameters (i.e. the same leading dimension as the
          :code:`y_true` and :code:`y_pred` parameters). This defaults to a list with
          a single entry of :code:`sample_weight` (as used by many SciKit-Learn
          metrics). If :code:`None` or an empty list is supplied, then no parameters
          will be treated as sample parameters.
  
      Returns
      -------
      callable
          Function with the same signature as the :code:`metric` but with additional
          :code:`sensitive_features=` and :code:`method=` arguments, to enable the
          required computation
      """
      dm = _DerivedMetric(
          metric=metric,
          transform=transform,
          sample_param_names=sample_param_names,
      )
      return dm
  
imports: import functools
  import inspect
  from typing import Callable, List, Union
  from ._metric_frame import MetricFrame
label_desc: Use image node_id 1 for calling a global function with example usage: make_derived_metric() and returns: dm