gFair

class fairdiverse.search.preprocessing_model.gFair.gFair(configs, dataset)[source]

Bases: PreprocessingFairnessIntervention

gFair is a fairness intervention method based on optimization techniques.

This class extends PreprocessingFairnessIntervention and applies group fairness constraints to data using probabilistic mapping and distance-based optimization.

fit(X_train, run)[source]

Train the gFair fairness model using the given training dataset.

This method applies optimization to learn group fairness constraints and stores the results for later use.

:param X_trainpandas.DataFrame

The training dataset. The last column is expected to be the protected attribute.

:param runstr

The identifier for the training run.

:return : None

transform(X, run, file_name=None)[source]

Apply the fairness transformation to the dataset using the learned model.

This method ensures fairness by adjusting feature distributions while maintaining data utility.

:param Xpandas.DataFrame

The dataset to which the fairness transformation is applied.

:param runstr

The identifier for the transformation run.

:param file_namestr, optional

Name of the file to save the transformed dataset.

:returnpandas.DataFrame

The dataset with transformed fair columns.