class_docstr: Reject option classification is a postprocessing technique that gives
  favorable outcomes to unpriviliged groups and unfavorable outcomes to
  priviliged groups in a confidence band around the decision boundary with the
  highest uncertainty [10]_.
  
  References:
      .. [10] F. Kamiran, A. Karim, and X. Zhang, "Decision Theory for
         Discrimination-Aware Classification," IEEE International Conference
         on Data Mining, 2012.
class_docstr_tok: ["Reject","option","classification","is","a","postprocessing","technique","that","gives","favorable","outcomes","to","unpriviliged","groups","and","unfavorable","outcomes","to","priviliged","groups","in","a","confidence","band","around","the","decision","boundary","with","the","highest","uncertainty","[","10","]","_.","References",":","..","[","10","]","F.","Kamiran",",","A.","Karim",",","and","X.","Zhang",",","``","Decision","Theory","for","Discrimination-Aware","Classification",",","''","IEEE","International","Conference","on","Data","Mining",",","2012","."]
docstr: Estimates the optimal classification threshold and margin for reject
  option classification that optimizes the metric provided.
  
  Note:
      The `fit` function is a no-op for this algorithm.
  
  Args:
      dataset_true (BinaryLabelDataset): Dataset containing the true
          `labels`.
      dataset_pred (BinaryLabelDataset): Dataset containing the predicted
          `scores`.
  
  Returns:
      RejectOptionClassification: Returns self.
docstr_tok: ["Estimates","the","optimal","classification","threshold","and","margin","for","reject","option","classification","that","optimizes","the","metric","provided",".","Note",":","The","`","fit","`","function","is","a","no-op","for","this","algorithm",".","Args",":","dataset_true","(","BinaryLabelDataset",")",":","Dataset","containing","the","true","`","labels","`",".","dataset_pred","(","BinaryLabelDataset",")",":","Dataset","containing","the","predicted","`","scores","`",".","Returns",":","RejectOptionClassification",":","Returns","self","."]
code: def fit(self, dataset_true, dataset_pred):
      """Estimates the optimal classification threshold and margin for reject
      option classification that optimizes the metric provided.
  
      Note:
          The `fit` function is a no-op for this algorithm.
  
      Args:
          dataset_true (BinaryLabelDataset): Dataset containing the true
              `labels`.
          dataset_pred (BinaryLabelDataset): Dataset containing the predicted
              `scores`.
  
      Returns:
          RejectOptionClassification: Returns self.
      """
  
      fair_metric_arr = np.zeros(
          self.num_class_thresh * self.num_ROC_margin
      )
      balanced_acc_arr = np.zeros_like(fair_metric_arr)
      ROC_margin_arr = np.zeros_like(fair_metric_arr)
      class_thresh_arr = np.zeros_like(fair_metric_arr)
  
      cnt = 0
      # Iterate through class thresholds
      for class_thresh in np.linspace(
          self.low_class_thresh,
          self.high_class_thresh,
          self.num_class_thresh,
      ):
          self.classification_threshold = class_thresh
          if class_thresh <= 0.5:
              low_ROC_margin = 0.0
              high_ROC_margin = class_thresh
          else:
              low_ROC_margin = 0.0
              high_ROC_margin = 1.0 - class_thresh
  
          # Iterate through ROC margins
          for ROC_margin in np.linspace(
              low_ROC_margin, high_ROC_margin, self.num_ROC_margin
          ):
              self.ROC_margin = ROC_margin
  
              # Predict using the current threshold and margin
              dataset_transf_pred = self.predict(dataset_pred)
  
              dataset_transf_metric_pred = BinaryLabelDatasetMetric(
                  dataset_transf_pred,
                  unprivileged_groups=self.unprivileged_groups,
                  privileged_groups=self.privileged_groups,
              )
              classified_transf_metric = ClassificationMetric(
                  dataset_true,
                  dataset_transf_pred,
                  unprivileged_groups=self.unprivileged_groups,
                  privileged_groups=self.privileged_groups,
              )
  
              ROC_margin_arr[cnt] = self.ROC_margin
              class_thresh_arr[cnt] = self.classification_threshold
  
              # Balanced accuracy and fairness metric computations
              balanced_acc_arr[cnt] = 0.5 * (
                  classified_transf_metric.true_positive_rate()
                  + classified_transf_metric.true_negative_rate()
              )
              if self.metric_name == "Statistical parity difference":
                  fair_metric_arr[
                      cnt
                  ] = dataset_transf_metric_pred.mean_difference()
              elif self.metric_name == "Average odds difference":
                  fair_metric_arr[
                      cnt
                  ] = classified_transf_metric.average_odds_difference()
              elif self.metric_name == "Equal opportunity difference":
                  fair_metric_arr[
                      cnt
                  ] = (
                      classified_transf_metric.equal_opportunity_difference()
                  )
  
              cnt += 1
  
      rel_inds = np.logical_and(
          fair_metric_arr >= self.metric_lb,
          fair_metric_arr <= self.metric_ub,
      )
      if any(rel_inds):
          best_ind = np.where(
              balanced_acc_arr[rel_inds]
              == np.max(balanced_acc_arr[rel_inds])
          )[0][0]
      else:
          warn("Unable to satisy fairness constraints")
          rel_inds = np.ones(len(fair_metric_arr), dtype=bool)
          best_ind = np.where(
              fair_metric_arr[rel_inds]
              == np.min(fair_metric_arr[rel_inds])
          )[0][0]
  
      self.ROC_margin = ROC_margin_arr[rel_inds][best_ind]
      self.classification_threshold = class_thresh_arr[rel_inds][
          best_ind
      ]
  
      return self
  
file_path: AIF360/aif360/algorithms/postprocessing/reject_option_classification.py
imports: import numpy
  from warnings import warn
  from aif360.algorithms import Transformer
  from aif360.metrics import utils
  from aif360.metrics import BinaryLabelDatasetMetric, ClassificationMetric
label_desc: Use image node_id 2 for calling the RejectOptionClassification obj's underlying member method code with example usage: obj.fit(dataset_true, dataset_pred) and returns: self