예제 #1
0
def test_missing_groups_transform_noglobal(dataset_with_single_grouping,
                                           scaling_range):
    X, y, groups, X_with_groups, grouper = dataset_with_single_grouping

    trf = MinMaxScaler(scaling_range)
    transformer = GroupedTransformer(trf,
                                     groups=grouper,
                                     use_global_model=False)
    transformer.fit(X_with_groups, y)

    # Array with 2 rows, first column a new group. Remaining top are out of range so should be the range
    X_test = np.concatenate([
        np.array([[3], [3]]),
        np.stack([X.min(axis=0) - 1, X.max(axis=0) + 1], axis=0)
    ],
                            axis=1)

    with pytest.raises(ValueError):
        transformer.transform(X_test)
예제 #2
0
def test_missing_groups_transform_global(dataset_with_single_grouping,
                                         scaling_range):
    X, y, groups, X_with_groups, grouper = dataset_with_single_grouping

    trf = MinMaxScaler(scaling_range)
    transformer = GroupedTransformer(trf, groups=grouper)
    transformer.fit(X_with_groups, y)

    # Array with 2 rows, first column a new group. Remaining top are out of range so should be the range
    X_test = np.concatenate([
        np.array([[3], [3]]),
        np.stack([X.min(axis=0), X.max(axis=0)], axis=0)
    ],
                            axis=1)

    transformed = transformer.transform(X_test)

    # Top row should all be equal to the small value of the range, bottom the other
    assert np.allclose(transformed[0, :], scaling_range[0])
    assert np.allclose(transformed[1, :], scaling_range[1])