forked from Trusted-AI/AIF360
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_standard_datasets.py
49 lines (39 loc) · 1.39 KB
/
test_standard_datasets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import numpy as np
import pandas as pd
pd.set_option('display.max_rows', 50)
pd.set_option('display.max_columns', 10)
pd.set_option('display.width', 200)
from aif360.datasets import AdultDataset
from aif360.datasets import BankDataset
from aif360.datasets import CompasDataset
from aif360.datasets import GermanDataset
from aif360.metrics import BinaryLabelDatasetMetric
def test_compas():
# just test that there are no errors for default loading...
cd = CompasDataset()
# print(cd)
def test_german():
gd = GermanDataset()
bldm = BinaryLabelDatasetMetric(gd)
assert bldm.num_instances() == 1000
def test_adult_test_set():
ad = AdultDataset()
# train, test = ad.split([32561])
train, test = ad.split([30162])
assert np.any(test.labels)
def test_adult():
ad = AdultDataset()
# print(ad.feature_names)
assert np.isclose(ad.labels.mean(), 0.2478, atol=5e-5)
bldm = BinaryLabelDatasetMetric(ad)
assert bldm.num_instances() == 45222
def test_adult_no_drop():
ad = AdultDataset(protected_attribute_names=['sex'],
privileged_classes=[['Male']], categorical_features=[],
features_to_keep=['age', 'education-num'])
bldm = BinaryLabelDatasetMetric(ad)
assert bldm.num_instances() == 48842