コード例 #1
0
def test_copy():
    sd = StructuredDataset(df=df, label_names=['label'], protected_attribute_names=['two'])
    sd2 = sd.copy()
    sd3 = sd.copy(True)

    sd.features[0] = 999
    assert np.all(sd2.features[0] == 999)
    assert not np.any(sd3.features[0] == 999)
コード例 #2
0
def test_eq():
    sd = StructuredDataset(df=df, label_names=['label'], protected_attribute_names=['two'])
    sd2 = sd.copy()
    sd3 = sd.copy(True)
    sd4 = StructuredDataset(df=df, label_names=['label'], protected_attribute_names=['one', 'three'])

    assert sd == sd2
    assert sd == sd3
    assert sd2 == sd3
    assert sd != sd4
コード例 #3
0
def test_temporarily_ignore():
    sd = StructuredDataset(df=df, label_names=['label'], protected_attribute_names=['one', 'three'])
    modified = sd.copy()
    modified.labels = sd.labels + 1
    assert sd != modified
    with sd.temporarily_ignore('labels'):
        assert sd == modified
    assert 'labels' not in sd.ignore_fields
コード例 #4
0
from aif360.datasets import StructuredDataset
from aif360.metrics import SampleDistortionMetric

data = np.arange(12).reshape((3, 4)).T
cols = ['one', 'two', 'three', 'label']
labs = np.ones((4, 1))

df = pd.DataFrame(data=np.concatenate((data, labs), axis=1), columns=cols)
sd = StructuredDataset(df=df,
                       label_names=['label'],
                       protected_attribute_names=['one', 'three'])

distorted = data + 1

sd_distorted = sd.copy(True)
sd_distorted.features = distorted

rand = np.random.randint(0, 10, (4, 4))
rand2 = np.random.randint(0, 10, (4, 3))
df_rand = pd.DataFrame(data=rand, columns=cols)
sd_rand = StructuredDataset(df=df_rand,
                            label_names=['label'],
                            protected_attribute_names=['one', 'three'])
sd_rand2 = sd_rand.copy(True)
sd_rand2.features = rand2

priv = [{'one': 1}]
unpriv = [{'one': 2}]