def test_frozen_featurizer_1(data):
    ff = FrozenFeaturizer(data[0])
    ff_features = ff.fit_transform(data[1])
    assert ff_features.shape == (10, 11)
    ff_features = ff.fit_transform(data[1], depth=1)
    assert ff_features.shape == (10, 4)
    ff_features = ff.fit_transform(data[1])
    assert ff_features.shape == (10, 11)
def test_frozen_featurizer_3(data):
    ff = FrozenFeaturizer(data[0])
    try:
        ff.feature_labels
    except ValueError:
        assert True
    else:
        assert False, 'should got ValueError'
    ff.fit_transform(data[2])
    try:
        ff.feature_labels
    except ValueError:
        assert False
def test_frozen_featurizer_2(data):
    ff = FrozenFeaturizer(data[0])
    ff_features = ff.fit_transform(data[2])
    assert ff_features.shape == (10, 11)
    assert isinstance(ff_features, pd.DataFrame)
    assert ff_features.index.tolist() == list(data[3])

    _hlayers = [7, 4]
    labels = [
        'L(' + str(i - len(_hlayers)) + ')_' + str(j + 1) for i in range(2)
        for j in range(_hlayers[i])
    ]
    assert ff_features.columns.tolist() == list(labels)
Exemple #4
0
def test_frozen_featurizer_5(data):
    ff = FrozenFeaturizer(data[0])

    with pytest.warns(
            UserWarning,
            match='is over the max depth of hidden layers starting at the given'
    ):
        ff_features = ff.fit_transform(data[1], depth=2, n_layer=3)
        assert ff_features.shape == (10, 11)
    with pytest.warns(UserWarning,
                      match='is greater than the max depth of hidden layers'):
        ff_features = ff.fit_transform(data[4], depth=3, n_layer=2)
        assert ff_features.shape == (20, 11)

    ff = FrozenFeaturizer(data[5])
    ff_features = ff.transform(data[1], depth=2, return_type='df')

    desc_ori = []
    for i in [1, 2]:
        desc_ori.append(ff_features[ff_features.columns[[
            f'L(-{i})' in s for s in ff_features.columns.values
        ]]])

    desc_new = []
    for i in [1, 2]:
        for j in [1, 2]:
            desc_new.append(
                ff.transform(data[1], depth=j, n_layer=i, return_type='df'))

    for i in range(2):
        tmp = desc_new[i] == desc_ori[i]
        assert all(tmp.all())
Exemple #5
0
def test_frozen_featurizer_3(data):
    ff = FrozenFeaturizer(data[0])
    with pytest.raises(ValueError):
        ff.feature_labels
    ff.fit_transform(data[2])
    ff.feature_labels

    ff = FrozenFeaturizer(data[5])
    with pytest.raises(ValueError):
        ff.feature_labels
    ff.fit_transform(data[2])
    ff.feature_labels
Exemple #6
0
def test_frozen_featurizer_4(data):
    ff = FrozenFeaturizer(data[0])
    ff_features = ff.fit_transform(data[1])
    assert ff_features.shape == (10, 11)
    ff_features = ff.fit_transform(data[4])
    assert ff_features.shape == (20, 11)

    ff = FrozenFeaturizer(data[5])
    ff_features = ff.fit_transform(data[1])
    assert ff_features.shape == (10, 11)
    ff_features = ff.fit_transform(data[4])
    assert ff_features.shape == (20, 11)