def test_normalize_max(random_df): data = random_df normalized = utils.normalize(data, "max") # check max index didx = data.idxmax(axis=1) nidx = normalized.idxmax(axis=1) assert (didx == nidx).all() # check max equals to 1 assert np.isclose(normalized.max(axis=1).values, 1).all()
def test_normalize_sum(random_df): data = random_df normalized = utils.normalize(data, "sum") # check max index didx = data.idxmax(axis=1) nidx = normalized.idxmax(axis=1) assert (didx == nidx).all() # check that each row sums 1 assert np.isclose(normalized.sum(axis=1).values, 1).all()
def test_normalize_invalid_mode(random_df): data = random_df with pytest.raises(ValueError): utils.normalize(data, "invalid_mode")
def test_normalize_feature(random_df): data = random_df ft = data.columns[25] normalized = utils.normalize(data, "feature", ft) assert np.isclose(normalized[ft], 1).all()
def test_normalize_euclidean(random_df): data = random_df normalized = utils.normalize(data, "euclidean") norm = normalized.apply(lambda x: np.linalg.norm(x), axis=1) assert np.isclose(norm, 1).all()
def test_normalize_max(random_df): data = random_df normalized = utils.normalize(data, "max") assert np.isclose(normalized.max(axis=1).values, 1).all()
def test_normalize_sum(random_df): data = random_df normalized = utils.normalize(data, "sum") assert np.isclose(normalized.sum(axis=1).values, 1).all()