code: def demographic_parity_difference(
      y_true,
      y_pred,
      *,
      sensitive_features,
      method="between_groups",
      sample_weight=None,
  ) -> float:
      """Calculate the demographic parity difference.
  
      The demographic parity difference is defined as the difference
      between the largest and the smallest group-level selection rate,
      :math:`E[h(X) | A=a]`, across all values :math:`a` of the sensitive feature(s).
      The demographic parity difference of 0 means that all groups have the same selection rate.
  
      Read more in the :ref:`User Guide <disparity_metrics>`.
  
      Parameters
      ----------
      y_true : array-like
          Ground truth (correct) labels.
  
      y_pred : array-like
          Predicted labels :math:`h(X)` returned by the classifier.
  
      sensitive_features : array-like
          The sensitive features over which demographic parity should be assessed
  
      method : str
          How to compute the differences. See :func:`fairlearn.metrics.MetricFrame.difference`
          for details.
  
      sample_weight : array-like
          The sample weights
  
      Returns
      -------
      float
          The demographic parity difference
      """
      sel_rate = MetricFrame(
          metrics=selection_rate,
          y_true=y_true,
          y_pred=y_pred,
          sensitive_features=sensitive_features,
          sample_params={"sample_weight": sample_weight},
      )
      result = sel_rate.difference(method=method)
      return result
  
file_path: fairlearn/fairlearn/metrics/_fairness_metrics.py
imports: from ._base_metrics import false_positive_rate, selection_rate, true_positive_rate
  from ._metric_frame import MetricFrame
label_desc: Use image node_id 1 for calling a global function with example usage: demographic_parity_difference(y_true, y_pred) and returns: result