Esempio n. 1
0
def test_fit():
    X = X_dsel_ex1
    y = y_dsel_ex1
    pool_classifiers = create_pool_classifiers()
    single_best_test = SingleBest(pool_classifiers)
    single_best_test.fit(X, y)

    assert single_best_test.best_clf_index == 0 or single_best_test.best_clf_index == 2
Esempio n. 2
0
def test_predict():
    X = X_dsel_ex1
    y = y_dsel_ex1
    pool_classifiers = create_pool_classifiers()
    single_best_test = SingleBest(pool_classifiers)
    single_best_test.fit(X, y)

    predicted_labels = single_best_test.predict(X)
    assert np.equal(predicted_labels, 0).all()
Esempio n. 3
0
def test_fit(create_X_y, create_pool_classifiers):
    X, y = create_X_y

    pool_classifiers = create_pool_classifiers
    single_best_test = SingleBest(pool_classifiers)
    single_best_test.fit(X, y)

    assert (single_best_test.best_clf_index_ == 0
            or single_best_test.best_clf_index_ == 2)
Esempio n. 4
0
def test_predict_proba():
    X = X_dsel_ex1
    y = y_dsel_ex1
    pool_classifiers = create_pool_classifiers()
    single_best_test = SingleBest(pool_classifiers)
    single_best_test.fit(X, y)

    predicted_proba = single_best_test.predict_proba(X)
    assert np.equal(predicted_proba, pool_classifiers[0].predict_proba(X)).all()
Esempio n. 5
0
def test_predict(create_X_y, create_pool_classifiers):
    X, y = create_X_y

    pool_classifiers = create_pool_classifiers
    single_best_test = SingleBest(pool_classifiers=pool_classifiers)
    single_best_test.fit(X, y)

    predicted_labels = single_best_test.predict(X)
    assert np.equal(predicted_labels, 0).all()
Esempio n. 6
0
def test_predict_proba(create_X_y, create_pool_classifiers):
    X, y = create_X_y

    pool_classifiers = create_pool_classifiers
    single_best_test = SingleBest(pool_classifiers)
    single_best_test.fit(X, y)

    predicted_proba = single_best_test.predict_proba(X)
    assert np.equal(predicted_proba,
                    pool_classifiers[0].predict_proba(X)).all()
Esempio n. 7
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)
    sb = SingleBest(pool)
    sb.fit(X, y)
    pred = sb.predict(X)
    assert np.isin(sb.classes_, pred).all()
Esempio n. 8
0
def test_fit(create_X_y, create_pool_classifiers):
    X, y = create_X_y

    pool_classifiers = create_pool_classifiers
    single_best_test = SingleBest(pool_classifiers)
    single_best_test._estimate_performances = MagicMock(
        return_value=[1.0, 0.5, 0.99])

    single_best_test.fit(X, y)

    assert single_best_test.best_clf_index_ == 0
Esempio n. 9
0
def test_different_scorer():
    X, y = make_classification(n_samples=100, random_state=42)
    X_val, y_val = make_classification(n_samples=25, random_state=123)
    pool = AdaBoostClassifier(n_estimators=10).fit(X, y)
    performances = []
    for clf in pool:
        preds = clf.predict_proba(X_val)
        performances.append(roc_auc_score(y_val.ravel(), preds[:, -1]))
    id_best = np.argmax(performances)
    sb = SingleBest(pool_classifiers=pool, scoring='roc_auc')
    sb.fit(X_val, y_val)
    assert id_best == sb.best_clf_index_
Esempio n. 10
0
def test_not_predict_proba():
    X = X_dsel_ex1
    y = y_dsel_ex1
    classifier = MagicMock()
    classifier.predict.return_value = [0]
    single_best_test = SingleBest([classifier] * 10)
    single_best_test.fit(X, y)
    with pytest.raises(ValueError):
        single_best_test.predict_proba(X)
Esempio n. 11
0
def test_not_predict_proba(create_X_y):
    X, y = create_X_y

    classifier = MagicMock()
    classifier.predict.return_value = [0]
    single_best_test = SingleBest([classifier] * 10)
    single_best_test.fit(X, y)
    with pytest.raises(ValueError):
        single_best_test.predict_proba(X)
Esempio n. 12
0
def test_single_best():
    pool_classifiers, X_dsel, y_dsel, X_test, y_test = setup_classifiers()

    single_best = SingleBest(pool_classifiers)
    single_best.fit(X_dsel, y_dsel)
    assert np.isclose(single_best.score(X_test, y_test), 0.86969696969696975)
Esempio n. 13
0
def test_not_fitted():
    single_best_test = SingleBest(create_pool_classifiers())
    with pytest.raises(NotFittedError):
        single_best_test.predict(np.array([1, -1]))
Esempio n. 14
0
def test_not_fitted():
    single_best_test = SingleBest()
    with pytest.raises(NotFittedError):
        single_best_test.predict(np.array([[1, -1]]))
Esempio n. 15
0
def test_label_encoder(create_label_encoder_test):
    X, y, pool = create_label_encoder_test
    sb = SingleBest(pool).fit(X, y)
    pred = sb.predict(X)
    assert np.array_equal(pred, y)
Esempio n. 16
0
def test_check_estimator():
    check_estimator(SingleBest())