Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_conditional():
sdm = SampleDistortionMetric(sd, sd_distorted, unprivileged_groups=unpriv,
privileged_groups=priv)
assert sdm.total_manhattan_distance(privileged=False) == 3
def test_euclidean_distance():
sdm = SampleDistortionMetric(sd, sd_distorted)
assert sdm.total_euclidean_distance() == 4*np.sqrt(3)
def test_mahalanobis_distance():
sdm = SampleDistortionMetric(sd_rand, sd_rand2)
assert np.isclose(sdm.total_mahalanobis_distance(),
np.diag(cdist(rand[:, :3], rand2[:, :3], 'mahalanobis')).sum())
def test_average():
sd_distorted.features[-1, -1] += 1
sd.instance_weights = sd_distorted.instance_weights = np.array([1, 1, 1, 3])
sdm = SampleDistortionMetric(sd, sd_distorted)
assert sdm.average_manhattan_distance() == 3.5
def test_error():
try:
sd.protected_attributes -= 1
sdm = SampleDistortionMetric(sd, sd_distorted)
except ValueError:
assert True
def test_manhattan_distance():
sdm = SampleDistortionMetric(sd, sd_distorted)
assert sdm.total_manhattan_distance() == 12