class_docstr: Metrics that can be used to evaluate the following fairness metrics.
  
    * Demographic Parity or Equality of Outcomes.
      For each slice measure the Positive* Rate, or the percentage of all
      examples receiving positive scores.
    * Equality of Opportunity
      Equality of Opportunity attempts to match the True Positive* rate
      (aka recall) of different data slices.
    * Equality of Odds
      In addition to looking at Equality of Opportunity, looks at equalizing the
      False Positive* rates of slices as well.
  
  The choice to focus on these metrics as a starting point is based primarily on
  the paper Equality of Opportunity in Supervised Learning and the excellent
  visualization created as a companion to the paper.
  
  https://arxiv.org/abs/1610.02413
  http://research.google.com/bigpicture/attacking-discrimination-in-ml/
  
  * Note that these fairness formulations assume that a positive prediction is
  associated with a positive outcome for the user--in certain contexts such as
  abuse, positive predictions translate to non-opportunity. You may want to use
  the provided negative rates for comparison instead.
class_docstr_tok: ["Metrics","that","can","be","used","to","evaluate","the","following","fairness","metrics",".","*","Demographic","Parity","or","Equality","of","Outcomes",".","For","each","slice","measure","the","Positive","*","Rate",",","or","the","percentage","of","all","examples","receiving","positive","scores",".","*","Equality","of","Opportunity","Equality","of","Opportunity","attempts","to","match","the","True","Positive","*","rate","(","aka","recall",")","of","different","data","slices",".","*","Equality","of","Odds","In","addition","to","looking","at","Equality","of","Opportunity",",","looks","at","equalizing","the","False","Positive","*","rates","of","slices","as","well",".","The","choice","to","focus","on","these","metrics","as","a","starting","point","is","based","primarily","on","the","paper","Equality","of","Opportunity","in","Supervised","Learning","and","the","excellent","visualization","created","as","a","companion","to","the","paper",".","https",":","\/\/arxiv.org\/abs\/1610.02413","http",":","\/\/research.google.com\/bigpicture\/attacking-discrimination-in-ml\/","*","Note","that","these","fairness","formulations","assume","that","a","positive","prediction","is","associated","with","a","positive","outcome","for","the","user","--","in","certain","contexts","such","as","abuse",",","positive","predictions","translate","to","non-opportunity",".","You","may","want","to","use","the","provided","negative","rates","for","comparison","instead","."]
code: def populate_stats_and_pop(
      self,
      unused_slice_key: slicer.SliceKeyType,
      combine_metrics: Dict[str, Any],
      output_metrics: Dict[str, metrics_pb2.MetricValue],
  ) -> None:
      matrices = combine_metrics.pop(
          self._metric_key(self.matrices_key)
      )
      thresholds = combine_metrics.pop(
          self._metric_key(self.thresholds_key)
      )
  
      # We assume that thresholds are already sorted.
      if len(matrices) != len(thresholds):
          raise ValueError(
              "matrices should have the same length as thresholds, but lengths "
              "were: matrices: %d, thresholds: %d"
              % (len(matrices), len(thresholds))
          )
      for threshold, raw_matrix in zip(thresholds, matrices):
          # Adds confusion matrix table as well as ratios used for fairness metrics.
          if isinstance(threshold, types.ValueWithTDistribution):
              threshold = threshold.unsampled_value
          output_matrix = (
              post_export_metrics._create_confusion_matrix_proto(
                  raw_matrix, threshold
              )
          )
          (
              output_metrics[
                  self._metric_key(
                      metric_keys.FAIRNESS_CONFUSION_MATRIX
                  )
              ]
              .confusion_matrix_at_thresholds.matrices.add()
              .CopyFrom(output_matrix)
          )
  
file_path: model-analysis/tensorflow_model_analysis/addons/fairness/post_export_metrics/fairness_indicators.py
imports: from typing import Any, Dict, List, Optional, Tuple
  import tensorflow
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.post_export_metrics import metric_keys
  from tensorflow_model_analysis.post_export_metrics import post_export_metrics
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
label_desc: Use image node_id 3 for calling the _FairnessIndicators obj's underlying member method code with example usage: obj.populate_stats_and_pop(unused_slice_key, combine_metrics, output_metrics) without return types