import os
from abc import ABC, abstractmethod
from pathlib import Path
[docs]
class PreprocessingFairnessIntervention(ABC):
"""
Abstract base class for preprocessing fairness interventions.
This class serves as a base for various fairness intervention methods that preprocess datasets
to reduce biases while maintaining data utility.
"""
def __init__(self, configs, dataset):
"""
Initialize the fairness intervention with the given configurations and dataset.
This method sets up the necessary directories for storing model parameters and
fair data transformations.
:param configs : dict
Configuration dictionary containing model parameters and paths.
:param dataset : object
Dataset object containing path information.
Attributes:
- self.dataset : object
Stores the dataset object for reference.
- self.configs : dict
Stores the configuration parameters.
- self.model_path : Path
Directory path where model parameters will be stored.
- self.fair_data_path : Path
Directory path where transformed fair data will be stored.
Note:
- The necessary directories are automatically created if they do not exist.
"""
self.dataset = dataset
self.configs = configs
self.model_path = Path(self.dataset.path) / self.configs["name"] / "model_params"
os.makedirs(self.model_path, exist_ok=True)
self.fair_data_path = Path(self.dataset.path) / self.configs["name"] / "fair_data"
os.makedirs(self.fair_data_path, exist_ok=True)
[docs]
@abstractmethod
def fit(self, X_train, run):
"""
Train the fairness model using the given training dataset.
:param X_train : pandas.DataFrame
The training dataset.
:param run : str
The identifier for the training run when using k-fold.
:return : None
"""
pass