class_docstr: Calibrated equalized odds post-processor.
  
  Calibrated equalized odds is a post-processing technique that optimizes over
  calibrated classifier score outputs to find probabilities with which to
  change output labels with an equalized odds objective [#pleiss17]_.
  
  Note:
      A :class:`~sklearn.pipeline.Pipeline` expects a single estimation step
      but this class requires an estimator's predictions as input. See
      :class:`PostProcessingMeta` for a workaround.
  
  See also:
      :class:`PostProcessingMeta`
  
  References:
      .. [#pleiss17] `G. Pleiss, M. Raghavan, F. Wu, J. Kleinberg, and
         K. Q. Weinberger, "On Fairness and Calibration," Conference on Neural
         Information Processing Systems, 2017.
         <http://papers.nips.cc/paper/7151-on-fairness-and-calibration.pdf>`_
  
  Adapted from:
  https://github.com/gpleiss/equalized_odds_and_calibration/blob/master/calib_eq_odds.py
  
  Attributes:
      prot_attr_ (str or list(str)): Protected attribute(s) used for post-
          processing.
      groups_ (array, shape (2,)): A list of group labels known to the
          classifier. Note: this algorithm require a binary division of the
          data.
      classes_ (array, shape (num_classes,)): A list of class labels known to
          the classifier. Note: this algorithm treats all non-positive
          outcomes as negative (binary classification only).
      pos_label_ (scalar): The label of the positive class.
      mix_rates_ (array, shape (2,)): The interpolation parameters -- the
          probability of randomly returning the group's base rate. The group
          for which the cost function is higher is set to 0.
class_docstr_tok: ["Calibrated","equalized","odds","post-processor",".","Calibrated","equalized","odds","is","a","post-processing","technique","that","optimizes","over","calibrated","classifier","score","outputs","to","find","probabilities","with","which","to","change","output","labels","with","an","equalized","odds","objective","[","#","pleiss17","]","_",".","Note",":","A",":","class",":","`","~sklearn.pipeline.Pipeline","`","expects","a","single","estimation","step","but","this","class","requires","an","estimator","'s","predictions","as","input",".","See",":","class",":","`","PostProcessingMeta","`","for","a","workaround",".","See","also",":",":","class",":","`","PostProcessingMeta","`","References",":","..","[","#","pleiss17","]","`","G.","Pleiss",",","M.","Raghavan",",","F.","Wu",",","J.","Kleinberg",",","and","K.","Q.","Weinberger",",","``","On","Fairness","and","Calibration",",","''","Conference","on","Neural","Information","Processing","Systems",",","2017",".","<","http",":","\/\/papers.nips.cc\/paper\/7151-on-fairness-and-calibration.pdf",">","`","_","Adapted","from",":","https",":","\/\/github.com\/gpleiss\/equalized_odds_and_calibration\/blob\/master\/calib_eq_odds.py","Attributes",":","prot_attr_","(","str","or","list","(","str",")",")",":","Protected","attribute","(","s",")","used","for","post-","processing",".","groups_","(","array",",","shape","(","2",",",")",")",":","A","list","of","group","labels","known","to","the","classifier",".","Note",":","this","algorithm","require","a","binary","division","of","the","data",".","classes_","(","array",",","shape","(","num_classes",",",")",")",":","A","list","of","class","labels","known","to","the","classifier",".","Note",":","this","algorithm","treats","all","non-positive","outcomes","as","negative","(","binary","classification","only",")",".","pos_label_","(","scalar",")",":","The","label","of","the","positive","class",".","mix_rates_","(","array",",","shape","(","2",",",")",")",":","The","interpolation","parameters","--","the","probability","of","randomly","returning","the","group","'s","base","rate",".","The","group","for","which","the","cost","function","is","higher","is","set","to","0","."]
docstr: Compute the mixing rates required to satisfy the cost constraint.
  
  Args:
      X (array-like): Probability estimates of the targets as returned by
          a ``predict_proba()`` call or equivalent.
      y (pandas.Series): Ground-truth (correct) target values.
      labels (list, optional): The ordered set of labels values. Must
          match the order of columns in X if provided. By default,
          all labels in y are used in sorted order.
      pos_label (scalar, optional): The label of the positive class.
      sample_weight (array-like, optional): Sample weights.
  
  Returns:
      self
docstr_tok: ["Compute","the","mixing","rates","required","to","satisfy","the","cost","constraint",".","Args",":","X","(","array-like",")",":","Probability","estimates","of","the","targets","as","returned","by","a","``","predict_proba","(",")","``","call","or","equivalent",".","y","(","pandas.Series",")",":","Ground-truth","(","correct",")","target","values",".","labels","(","list",",","optional",")",":","The","ordered","set","of","labels","values",".","Must","match","the","order","of","columns","in","X","if","provided",".","By","default",",","all","labels","in","y","are","used","in","sorted","order",".","pos_label","(","scalar",",","optional",")",":","The","label","of","the","positive","class",".","sample_weight","(","array-like",",","optional",")",":","Sample","weights",".","Returns",":","self"]
code: def fit(self, X, y, labels=None, pos_label=1, sample_weight=None):
      """Compute the mixing rates required to satisfy the cost constraint.
  
      Args:
          X (array-like): Probability estimates of the targets as returned by
              a ``predict_proba()`` call or equivalent.
          y (pandas.Series): Ground-truth (correct) target values.
          labels (list, optional): The ordered set of labels values. Must
              match the order of columns in X if provided. By default,
              all labels in y are used in sorted order.
          pos_label (scalar, optional): The label of the positive class.
          sample_weight (array-like, optional): Sample weights.
  
      Returns:
          self
      """
      X, y, sample_weight = check_inputs(X, y, sample_weight)
      groups, self.prot_attr_ = check_groups(
          y, self.prot_attr, ensure_binary=True
      )
      self.classes_ = (
          np.array(labels) if labels is not None else np.unique(y)
      )
      self.groups_ = np.unique(groups)
      self.pos_label_ = pos_label
  
      if len(self.classes_) != 2:
          raise ValueError("Only binary classification is supported.")
      if len(self.classes_) != X.shape[1]:
          raise ValueError(
              "Only binary classification is supported. X should"
              " contain one column per class. Got: {} columns.".format(
                  X.shape[1]
              )
          )
  
      if pos_label not in self.classes_:
          raise ValueError(
              "pos_label={} is not in the set of labels. The "
              "valid values are:\n{}".format(pos_label, self.classes_)
          )
  
      pos_idx = np.nonzero(self.classes_ == self.pos_label_)[0][0]
      try:
          X = X.iloc[:, pos_idx]
      except AttributeError:
          X = X[:, pos_idx]
  
      # local function to evaluate corresponding metric
      def _eval(func, grp_idx, trivial=False):
          idx = groups == self.groups_[grp_idx]
          pred = (
              np.full_like(X, self.base_rates_[grp_idx])
              if trivial
              else X
          )
          return func(
              y[idx],
              pred[idx],
              pos_label=pos_label,
              sample_weight=sample_weight[idx],
          )
  
      self.base_rates_ = [_eval(base_rate, i) for i in range(2)]
  
      costs = np.array(
          [
              [_eval(self._weighted_cost, i, t) for i in range(2)]
              for t in (False, True)
          ]
      )
      self.mix_rates_ = [
          (costs[0, 1] - costs[0, 0]) / (costs[1, 0] - costs[0, 0]),
          (costs[0, 0] - costs[0, 1]) / (costs[1, 1] - costs[0, 1]),
      ]
      self.mix_rates_[np.argmax(costs[0])] = 0
  
      return self
  
file_path: AIF360/aif360/sklearn/postprocessing/calibrated_equalized_odds.py
imports: import numpy
  from sklearn.base import BaseEstimator, ClassifierMixin
  from sklearn.utils import check_random_state
  from sklearn.utils.validation import check_is_fitted
  from aif360.sklearn.metrics import difference, base_rate
  from aif360.sklearn.metrics import generalized_fnr, generalized_fpr
  from aif360.sklearn.utils import check_inputs, check_groups
label_desc: Use image node_id 4 for calling the CalibratedEqualizedOdds obj's underlying member method code with example usage: obj.fit(X, y, labels, pos_label, sample_weight) and returns: self, func