docstr: Fits the sampler to the data.
  
  Updates observed prevalence in the reference group and calculates sampling rates
  for every group in the dataset.
  
  Parameters
  ----------
  X : pandas.DataFrame
      Feature matrix.
  y : pandas.Series
      Label vector.
  s : pandas.Series
      Protected attribute vector.
code: def fit(
      self, X: pd.DataFrame, y: pd.Series, s: Optional[pd.Series]
  ) -> None:
      """Fits the sampler to the data.
  
      Updates observed prevalence in the reference group and calculates sampling rates
      for every group in the dataset.
  
      Parameters
      ----------
      X : pandas.DataFrame
          Feature matrix.
      y : pandas.Series
          Label vector.
      s : pandas.Series
          Protected attribute vector.
      """
      self.logger.info("Fitting sampling method.")
  
      if s is None:
          raise ValueError("Sensitive Attribute `s` not passed.")
  
      if self.s_ref is None:  # Get more frequent group.
          self.s_ref = s.mode().values[0]
  
      self.or_prevalence = {}
      for group in s.unique():
          self.or_prevalence[group] = y[
              s == group
          ].mean()  # Assuming 0/1 label.
      if self.s_ref == "global":
          self.ref_prevalence = y.mean()
      else:
          self.ref_prevalence = self.or_prevalence[self.s_ref]
  
      self.logger.debug(
          f"Original prevalence by group: {self.or_prevalence}"
      )
  
      self.sampling_rate = {}
  
      for group in s.unique():
          if group == self.s_ref:
              continue  # No need to calculate sampling rates for reference group.
  
          positives = y[(s == group) & (y == 1)].shape[0]
          negatives = y[(s == group) & (y == 0)].shape[0]
  
          self.logger.debug(
              f"Calculating sampling size for group {group}."
          )
  
          self.sampling_rate[group] = self.calculate_sample_sizes(
              positives,
              negatives,
              self.ref_prevalence,
              self.strategy,
              self.alpha,
          )
          self.logger.debug(
              f"Sampling for group {group}: {self.sampling_rate[group]}"
          )
      self.logger.info("Sampling method fitted.")
  
file_path: aequitas/src/aequitas/fairflow/methods/preprocessing/prevalence_sample.py
imports: from typing import Any, Optional
  import pandas
  from ...utils import create_logger
  from .preprocessing import PreProcessing
label_desc: Use image node_id 2 for calling the PrevalenceSampling obj's underlying member method code with example usage: obj.fit(X, y, s) without return types