docstr: Creates a model from the Fairlearn package.
  
  Especially designed for the ExponentiatedGradient and GridSearch methods.
  
  Parameters
  ----------
  reduction : Union[str, callable]
      Reductions method. Either Exponentiated Gradient or Grid Search method. If
      string, it is imported during runtime.
  estimator : Union[str, callable]
      Base estimator for the reductions method. If string, it is imported during
      runtime.
  constraint: Union[str, Moment]
      Constraint for the reductions method. Must be a Moment from the Fairlearn
      package.
  **kwargs : dict, optional
      A dictionary containing the hyperparameters for the reduction method, base
      estimator and constraint. Parameters for the base estimator should be
      included with the prefix `model__`, and for the constraint with the prefix
      `constraint__`. Every other parameter will be passed down to the reductions
      method.
docstr_tok: ["Creates","a","model","from","the","Fairlearn","package",".","Especially","designed","for","the","ExponentiatedGradient","and","GridSearch","methods",".","Parameters","--","--","--","--","--","reduction",":","Union","[","str",",","callable","]","Reductions","method",".","Either","Exponentiated","Gradient","or","Grid","Search","method",".","If","string",",","it","is","imported","during","runtime",".","estimator",":","Union","[","str",",","callable","]","Base","estimator","for","the","reductions","method",".","If","string",",","it","is","imported","during","runtime",".","constraint",":","Union","[","str",",","Moment","]","Constraint","for","the","reductions","method",".","Must","be","a","Moment","from","the","Fairlearn","package",".","*","*","kwargs",":","dict",",","optional","A","dictionary","containing","the","hyperparameters","for","the","reduction","method",",","base","estimator","and","constraint",".","Parameters","for","the","base","estimator","should","be","included","with","the","prefix","`","model__","`",",","and","for","the","constraint","with","the","prefix","`","constraint__","`",".","Every","other","parameter","will","be","passed","down","to","the","reductions","method","."]
code: def __init__(
      self,
      reduction: Union[str, Union[object, Callable]],
      estimator: Union[str, Union[object, Callable]],
      constraint: Union[str, Union[object, Callable]],
      **kwargs,
  ):
      """Creates a model from the Fairlearn package.
  
      Especially designed for the ExponentiatedGradient and GridSearch methods.
  
      Parameters
      ----------
      reduction : Union[str, callable]
          Reductions method. Either Exponentiated Gradient or Grid Search method. If
          string, it is imported during runtime.
      estimator : Union[str, callable]
          Base estimator for the reductions method. If string, it is imported during
          runtime.
      constraint: Union[str, Moment]
          Constraint for the reductions method. Must be a Moment from the Fairlearn
          package.
      **kwargs : dict, optional
          A dictionary containing the hyperparameters for the reduction method, base
          estimator and constraint. Parameters for the base estimator should be
          included with the prefix `model__`, and for the constraint with the prefix
          `constraint__`. Every other parameter will be passed down to the reductions
          method.
      """
      self.logger = create_logger(
          "methods.inprocessing.ExponentiatedGradient"
      )
      # Importing any object that was passed down as string.
      if isinstance(reduction, str):
          self.logger.debug(f"Importing reduction: '{reduction}'.")
          reduction = import_object(reduction)
      if isinstance(estimator, str):
          self.logger.debug(f"Importing estimator: '{estimator}'.")
          estimator = import_object(estimator)
      if isinstance(constraint, str):
          self.logger.debug(f"Importing constraint: '{constraint}'.")
          constraint = import_object(constraint)
  
      # Parse keyword arguments
      (
          self.model_kwargs,
          self.constraint_kwargs,
          self.kwargs,
      ) = self.parse_kwargs(kwargs)
  
      # Instantiate objects for the method
      self.logger.info(
          f"Instantiating estimator '{estimator}' with parameters:"
          f" {self.model_kwargs}."
      )
      self.estimator = estimator(**self.model_kwargs)
  
      self.logger.info(
          f"Instantiating constraint '{constraint}' with "
          f"parameters: {self.constraint_kwargs}."
      )
      self.constraint = constraint(**self.constraint_kwargs)
  
      self.logger.info(
          f"Instantiating reduction '{reduction}' with parameters:"
          f" {self.kwargs}."
      )
      self.reduction = reduction(
          estimator=self.estimator,
          constraints=self.constraint,
          **self.kwargs,
      )
  
      # Depending on reduction, use probability mass function method.
      if isinstance(self.reduction, ExponentiatedGradient):
          self.predict_proba_method = lambda clf: clf._pmf_predict
      else:
          self.predict_proba_method = lambda clf: clf.predict_proba
  
file_path: aequitas/src/aequitas/fairflow/methods/inprocessing/fairlearn_classifier.py
imports: from copy import deepcopy
  from typing import Any, Callable, Optional, Union
  import numpy
  import pandas
  from fairlearn.reductions import ExponentiatedGradient, GridSearch
  from fairlearn.reductions._grid_search._grid_generator import _GridGenerator
  from ...utils import create_logger, import_object
  from .inprocessing import InProcessing
label_desc: Use image node_id 1 to create a new FairlearnClassifier object from inherited base classes: InProcessing with example: obj = FairlearnClassifier(reduction, estimator, constraint)