def test_fetch_adult(): """Tests Adult Income dataset shapes with various options.""" adult = fetch_adult() assert len(adult) == 3 assert adult.X.shape == (45222, 13) assert fetch_adult(dropna=False).X.shape == (48842, 13) assert fetch_adult(numeric_only=True).X.shape == (48842, 7)
import numpy as np from sklearn.model_selection import GridSearchCV from sklearn.metrics import accuracy_score import tensorflow as tf from aif360.datasets import AdultDataset from aif360.sklearn.datasets import fetch_adult from aif360.algorithms.inprocessing import AdversarialDebiasing as OldAdversarialDebiasing from aif360.sklearn.inprocessing import AdversarialDebiasing X, y, sample_weight = fetch_adult(numeric_only=True) adult = AdultDataset(instance_weights_name='fnlwgt', categorical_features=[], features_to_keep=[ 'age', 'education-num', 'capital-gain', 'capital-loss', 'hours-per-week' ], features_to_drop=[]) def test_adv_debias_old_reproduce(): """Test that the old AdversarialDebiasing is reproducible.""" sess = tf.Session() old_adv_deb = OldAdversarialDebiasing(unprivileged_groups=[{ 'sex': 0 }], privileged_groups=[{ 'sex': 1 }], scope_name='old_classifier', sess=sess,
import numpy as np import pandas as pd from sklearn.model_selection import train_test_split from aif360.sklearn.datasets import fetch_adult from aif360.sklearn.metrics import statistical_parity_difference from aif360.sklearn.preprocessing import fairadapt X, y, sample_weight = fetch_adult( dropcols=['education', 'capital-gain', 'capital-loss', 'relationship']) X = X[0:5000] y = y[0:5000] (X_train, X_test, y_train, y_test) = train_test_split(X, y, train_size=0.8, random_state=1234567) def test_fairadapt_adult(): """Test that FairAdapt works when applied to Adult dataset.""" train_df = pd.concat([X_train, y_train], axis=1) adj_mat = pd.DataFrame(np.zeros( (len(train_df.columns), len(train_df.columns)), dtype=int), index=train_df.columns.values, columns=train_df.columns.values) # Construct the adjacency matrix of the causal graph adj_mat.loc[["sex", "age", "native-country"], [ "marital-status", "education-num", "workclass", "hours-per-week", "occupation", "annual-income" ]] = 1