Пример #1
0
def test_predict_diff(example_static_selection):
    X, y, pool = example_static_selection

    static_selection_test = StaticSelection(pool, 0.75)
    static_selection_test.fit(X, y)

    predicted_labels = static_selection_test.predict(X)
    assert np.equal(predicted_labels, 1).all()
Пример #2
0
def test_predict(example_static_selection, create_pool_classifiers):
    X, y, _ = example_static_selection

    static_selection_test = StaticSelection(create_pool_classifiers * 10, 0.25)
    static_selection_test.fit(X, y)

    predicted_labels = static_selection_test.predict(X)
    assert np.equal(predicted_labels, 0).all()
Пример #3
0
def test_predict():
    X = X_dsel_ex1
    y = y_dsel_ex1
    pool_classifiers = create_pool_classifiers_score(
        1, 25, 0.5) + create_pool_classifiers_score(0, 25, 1.0)
    static_selection_test = StaticSelection(pool_classifiers, 0.25)
    static_selection_test.fit(X, y)

    predicted_labels = static_selection_test.predict(X)
    assert np.equal(predicted_labels, 0).all()
Пример #4
0
def test_label_encoder_base_ensemble():
    from sklearn.ensemble import RandomForestClassifier
    X, y = make_classification()
    y[y == 1] = 2
    y = y.astype(np.float)
    pool = RandomForestClassifier().fit(X, y)
    ss = StaticSelection(pool)
    ss.fit(X, y)
    pred = ss.predict(X)
    assert np.isin(ss.classes_, pred).all()
Пример #5
0
def test_not_fitted():
    static_selection_test = StaticSelection(create_pool_classifiers(), 0.25)
    with pytest.raises(NotFittedError):
        static_selection_test.predict(np.array([1, -1]))
Пример #6
0
def test_label_encoder(create_label_encoder_test):
    X, y, pool = create_label_encoder_test
    static = StaticSelection(pool).fit(X, y)
    pred = static.predict(X)
    assert np.array_equal(pred, y)
Пример #7
0
def test_not_fitted():
    static_selection_test = StaticSelection()
    with pytest.raises(NotFittedError):
        static_selection_test.predict(np.array([[1, -1]]))