class_docstr: Model is an algorithm for learning classifiers that are fair with respect
  to rich subgroups.
  
  Rich subgroups are defined by (linear) functions over the sensitive
  attributes, and fairness notions are statistical: false positive, false
  negative, and statistical parity rates. This implementation uses a max of
  two regressions as a cost-sensitive classification oracle, and supports
  linear regression, support vector machines, decision trees, and kernel
  regression. For details see:
  
  References:
      .. [1] "Preventing Fairness Gerrymandering: Auditing and Learning for
         Subgroup Fairness." Michale Kearns, Seth Neel, Aaron Roth, Steven Wu.
         ICML '18.
      .. [2] "An Empirical Study of Rich Subgroup Fairness for Machine
         Learning". Michael Kearns, Seth Neel, Aaron Roth, Steven Wu. FAT '19.
docstr: Run Fictitious play to compute the approximately fair classifier.
  
  Args:
      dataset: dataset object with its own class definition in datasets
          folder inherits from class StandardDataset.
      early_termination: Terminate Early if Auditor can't find fairness
          violation of more than gamma.
  Returns:
      Self
docstr_tok: ["Run","Fictitious","play","to","compute","the","approximately","fair","classifier",".","Args",":","dataset",":","dataset","object","with","its","own","class","definition","in","datasets","folder","inherits","from","class","StandardDataset",".","early_termination",":","Terminate","Early","if","Auditor","ca","n't","find","fairness","violation","of","more","than","gamma",".","Returns",":","Self"]
code: def fit(self, dataset, early_termination=True):
      """Run Fictitious play to compute the approximately fair classifier.
  
      Args:
          dataset: dataset object with its own class definition in datasets
              folder inherits from class StandardDataset.
          early_termination: Terminate Early if Auditor can't find fairness
              violation of more than gamma.
      Returns:
          Self
      """
  
      # defining variables and data structures for algorithm
      X, X_prime, y = clean.extract_df_from_ds(dataset)
      learner = Learner(X, y, self.predictor)
      auditor = Auditor(dataset, self.fairness_def)
      history = ClassifierHistory()
  
      # initialize variables
      n = X.shape[0]
      costs_0, costs_1, X_0 = auditor.initialize_costs(n)
      metric_baseline = 0
      predictions = [0.0] * n
  
      # scaling variables for heatmap
      vmin = None
      vmax = None
  
      # print output variables
      errors = []
      fairness_violations = []
  
      iteration = 1
      while iteration < self.max_iters:
          # learner's best response: solve the CSC problem, get mixture decisions on X to update prediction probabilities
          history.append_classifier(
              learner.best_response(costs_0, costs_1)
          )
          error, predictions = learner.generate_predictions(
              history.get_most_recent(), predictions, iteration
          )
          # auditor's best response: find group, update costs
          metric_baseline = auditor.get_baseline(y, predictions)
          group = auditor.get_group(predictions, metric_baseline)
          costs_0, costs_1 = auditor.update_costs(
              costs_0, costs_1, group, self.C, iteration, self.gamma
          )
  
          # outputs
          errors.append(error)
          fairness_violations.append(group.weighted_disparity)
          self.print_outputs(iteration, error, group)
          vmin, vmax = self.save_heatmap(
              iteration,
              dataset,
              history.get_most_recent().predict(X),
              vmin,
              vmax,
          )
          iteration += 1
  
          # early termination:
          if (
              early_termination
              and (len(errors) >= 5)
              and (
                  (errors[-1] == errors[-2])
                  or fairness_violations[-1] == fairness_violations[-2]
              )
              and fairness_violations[-1] < self.gamma
          ):
              iteration = self.max_iters
  
      self.classifiers = history.classifiers
      self.errors = errors
      self.fairness_violations = fairness_violations
      return self
  
file_path: AIF360/aif360/algorithms/inprocessing/gerryfair_classifier.py
imports: import copy
  from aif360.algorithms.inprocessing.gerryfair import heatmap
  from aif360.algorithms.inprocessing.gerryfair.clean import array_to_tuple
  from aif360.algorithms.inprocessing.gerryfair.learner import Learner
  from aif360.algorithms.inprocessing.gerryfair.auditor import *
  from aif360.algorithms.inprocessing.gerryfair.classifier_history import ClassifierHistory
  from aif360.algorithms import Transformer
label_desc: Use image node_id 2 for calling the GerryFairClassifier obj's underlying member method code with example usage: obj.fit(dataset, early_termination) and returns: self