code: def test_2m_2sf_2cf():
      funcs = {"recall": skm.recall_score, "prec": skm.precision_score}
      s_p = {"recall": {"sample_weight": s_w}}
      sf = np.stack([g_1, g_3], axis=1)
      cf = {"cf1": g_2, "cf2": g_4}
  
      target = MetricFrame(
          metrics=funcs,
          y_true=y_t,
          y_pred=y_p,
          sensitive_features=sf,
          control_features=cf,
          sample_params=s_p,
      )
      assert target._user_supplied_callable is False
  
      assert isinstance(target.by_group, pd.DataFrame)
      assert target.by_group.shape == (16, 2)
      assert np.array_equal(
          target.by_group.index.names,
          ["cf1", "cf2", "sensitive_feature_0", "sensitive_feature_1"],
      )
  
      # Only check some isolated results, rather than all 32
      mask_a_f = np.logical_and((g_1 == "aa"), (g_2 == "f"))
      mask_b_g = np.logical_and((g_1 == "ba"), (g_2 == "g"))
      mask_k_q = np.logical_and((g_3 == "kk"), (g_4 == "q"))
  
      mask_f_q_a_k = np.logical_and(mask_a_f, mask_k_q)
      recall_f_q_a_k = skm.recall_score(
          y_t[mask_f_q_a_k],
          y_p[mask_f_q_a_k],
          sample_weight=s_w[mask_f_q_a_k],
      )
      prec_f_q_a_k = skm.precision_score(
          y_t[mask_f_q_a_k], y_p[mask_f_q_a_k]
      )
      assert (
          target.by_group["recall"][("f", "q", "aa", "kk")]
          == recall_f_q_a_k
      )
      assert (
          target.by_group["prec"][("f", "q", "aa", "kk")]
          == prec_f_q_a_k
      )
  
      mask_g_q_b_k = np.logical_and(mask_b_g, mask_k_q)
      recall_g_q_b_k = skm.recall_score(
          y_t[mask_g_q_b_k],
          y_p[mask_g_q_b_k],
          sample_weight=s_w[mask_g_q_b_k],
      )
      prec_g_q_b_k = skm.precision_score(
          y_t[mask_g_q_b_k], y_p[mask_g_q_b_k]
      )
      assert (
          target.by_group["recall"][("g", "q", "ba", "kk")]
          == recall_g_q_b_k
      )
      assert (
          target.by_group["prec"][("g", "q", "ba", "kk")]
          == prec_g_q_b_k
      )
  
file_path: fairlearn/test/unit/metrics/test_metricframe_by_group.py
imports: import numpy
  import pandas
  import pytest
  import sklearn.metrics
  from fairlearn.metrics import MetricFrame
  from .data_for_test import g_1, g_2, g_3, g_4, s_w, y_p, y_t
label_desc: Use image node_id 5 for calling a global function with example usage: test_2m_2sf_2cf() without return types