code: def reweight(protected, y, verbose=True):
      """Obtain weights for model training and mitigate bias in Statistical Parity.
  
      Method produces weights for each subgroup for each class.
      Firstly, it assumes that protected variable and class are
      independent and calculates expected probability of this
      certain event (that subgroup == a and class = c).
      Than it calculates the actual probability of this event
      based on empirical data. Finally the weight is quotient
      of those probabilities.
  
      Parameters
      -----------
      protected : np.ndarray (1d)
          Vector, preferably 1-dimensional np.ndarray containing strings,
          which denotes the membership to a subgroup.
          NOTE: List and pd.Series are also supported; however, if provided,
          they will be transformed into a np.ndarray (1d) with dtype 'U'.
      y : pd.Series or pd.DataFrame or np.ndarray (1d)
          Target variable with outputs / scores. It shall have the same length as `protected`
      verbose : bool
          Print messages about changes of types in 'y' and 'protected' (default is `True`).
  
      Returns
      -----------
      numpy.ndarray (1d)
          Array with sample (case) weights
  
      Notes
      -----------
      - https://link.springer.com/content/pdf/10.1007/s10115-011-0463-8.pdf
      """
      y = basic_checks.check_y(y, verbose)
      protected = basic_checks.check_protected(protected, verbose)
  
      if not len(y) == len(protected):
          raise ParameterCheckError(
              "protected and target (y) must have the same length"
          )
  
      weights = np.repeat(None, len(y))
  
      for subgroup in np.unique(protected):
          for c in np.unique(y):
              Xs = np.sum(protected == subgroup)
              Xc = np.sum(y == c)
              Xsc = np.sum((protected == subgroup) & (c == y))
              Wsc = (Xs * Xc) / (len(y) * Xsc)
  
              weights[(protected == subgroup) & (y == c)] = Wsc
  
      return weights
  
file_path: DALEX/python/dalex/dalex/fairness/_group_fairness/mitigation.py
imports: import copy
  import numpy
  import dalex.datasets
  from .None import checks
  from .._basics import checks
  from .._basics.exceptions import ParameterCheckError
  from ..._explainer import helper
label_desc: Use image node_id 1 for calling a global function with example usage: reweight(protected, y, verbose) and returns: weights