code: def assemble_ref_groups(
      disparities_table,
      ref_group_flag="_ref_group_value",
      specific_measures=None,
      label_score_ref=None,
  ):
      """
       Creates a dictionary of reference groups for each metric in a data_table.
  
      :param disparities_table: a disparity table. Output of bias.get_disparity or
           fairness.get_fairness functions
       :param ref_group_flag: string indicating column indicates reference group
           flag value. Default is '_ref_group_value'.
       :param specific_measures: Limits reference dictionary to only specified
           metrics in a data table. Default is None.
       :param label_score_ref: Defines a metric, ex: 'fpr' (false positive rate)
           from which to mimic reference group for label_value and score. Used for
           statistical significance calculations in Bias() class. Default is None.
  
       :return: A dictionary
      """
      ref_groups = {}
      ref_group_cols = set(
          disparities_table.columns[
              disparities_table.columns.str.contains(ref_group_flag)
          ]
      )
  
      # Note: specific measures is a set
      if specific_measures:
          if len(specific_measures) < 1:
              raise ValueError(
                  "At least one metric must be passed for which to "
                  "find refrence group."
              )
  
          specific_measures = specific_measures.union({label_score_ref})
          ref_group_cols = {
              measure + ref_group_flag
              for measure in specific_measures
              if measure + ref_group_flag in ref_group_cols
          }
  
      attributes = list(disparities_table.attribute_name.unique())
  
      for attribute in attributes:
          attr_table = disparities_table.loc[
              disparities_table["attribute_name"] == attribute
          ]
  
          attr_refs = {}
          for col in ref_group_cols:
              if col in (
                  "label" + ref_group_flag,
                  "score" + ref_group_flag,
              ):
                  continue
  
              metric_key = col.replace(ref_group_flag, "")
              attr_refs[metric_key] = attr_table.loc[
                  attr_table["attribute_name"] == attribute, col
              ].min()
          if label_score_ref:
              is_valid_label_ref = (
                  lambda label: label + ref_group_flag
                  in disparities_table.columns
              )
  
              if not is_valid_label_ref(label_score_ref):
                  try:
                      label_score_ref = next(
                          measure
                          for measure in specific_measures
                          if is_valid_label_ref(measure)
                      )
                      logging.warning(
                          "The specified reference measure for label "
                          "value and score is not included in the "
                          f"data frame. Using '{label_score_ref}' "
                          "reference group as label value and score "
                          "reference instead."
                      )
  
                  except StopIteration:
                      raise ValueError(
                          "None of metrics passed in 'specific_measures' are in dataframe."
                      )
  
              attr_refs["label_value"] = attr_refs[label_score_ref]
              attr_refs["score"] = attr_refs[label_score_ref]
  
          ref_groups[attribute] = attr_refs
  
      return ref_groups
  
imports: import logging
  import math
  import numpy
  import collections
  import seaborn
  import matplotlib.pyplot
  import matplotlib.colors
  import matplotlib.cm
  from aequitas import squarify_flipped
label_desc: Use image node_id 1 for calling a global function with example usage: assemble_ref_groups(disparities_table, ref_group_flag, specific_measures, label_score_ref) and returns: ref_groups