Trusted-AI / AIF360

A comprehensive set of fairness metrics for datasets and machine learning models, explanations for these metrics, and algorithms to mitigate bias in datasets and models.
https://aif360.res.ibm.com/
Apache License 2.0
2.46k stars 840 forks source link

Disparate Impact Remover doesn't seem to be working #241

Open akuzni2 opened 3 years ago

akuzni2 commented 3 years ago

I'm trying to run the disparate impact remover on a dataset - however after varying the repair value between 0 -> 1.0 I see no change in disparate impact metric.

Example: My dataset (df_encoded) looks like the below with around 600 samples.

image

dataset_train = StandardDataset(df_encoded, label_name='outcome',
                    favorable_classes=[0],
                    protected_attribute_names=['sensitive'],
                    privileged_classes=[[1]])

di_remover = DisparateImpactRemover(repair_level=1.0)
train_repd = di_remover.fit_transform(dataset_train)

privileged_groups = [{'sensitive': 1}]
unprivileged_groups = [{'sensitive': 0}]

metric_train_repd = BinaryLabelDatasetMetric(train_repd, 
                unprivileged_groups=unprivileged_groups,
                privileged_groups=privileged_groups)

explainer = MetricTextExplainer(metric_train_repd)
explainer.disparate_impact()

In my dataset i get a disparate impact of 0.71. When I change "repair_level" to 0 or 1.0 I see no change in disparate impact.

cjwillis48 commented 2 years ago

Was a solution found for this? I am seeing the same thing now

OnTheThirdDay commented 2 years ago

I think that is actually the intended result. You may compare the dataset before and after, and the disparate_impact_remover has adjusted the feature values.

pradeepdev-1995 commented 1 year ago

@OnTheThirdDay How can I compare the datasets( original dataset and the disparate impact removed dataset) through code?

OnTheThirdDay commented 1 year ago

@OnTheThirdDay How can I compare the datasets( original dataset and the disparate impact removed dataset) through code?

Hi @pradeepdev-1995 , I haven't followed this thread for long, so a bit forgot the context. To compare, you can export the dataset (e.g. into csv) and you can see the feature values are actually different, though the DI score is not changed.

pradeepdev-1995 commented 1 year ago
di_remover = DisparateImpactRemover(repair_level=1.0)
train_repd = di_remover.fit_transform(dataset_train)

How can I export the train_repd to csv? kindly share the code snippet for this.

OnTheThirdDay commented 1 year ago
di_remover = DisparateImpactRemover(repair_level=1.0)
train_repd = di_remover.fit_transform(dataset_train)

How can I export the train_repd to csv? kindly share the code snippet for this.

Use some api like .convert_to_dataframe() and to_csv()

pradeepdev-1995 commented 1 year ago

@OnTheThirdDay Checked with convert_to_dataframe function of AIF360 like this

di = DisparateImpactRemover(repair_level=1.0)
dir_dataset = di.fit_transform(dataset)
dir_dataset_df= dir_dataset.convert_to_dataframe(sep=",")

print(originalDataset.equals(dir_dataset_df[0]))

But it shows that original and transformed datasets are the same. Which means DisparateImpactRemover nothing changed in the dataset even the repair_level=1.0