Example #1
0
def test_input_shape_fit():
    X = np.ones((15, 2))
    y = np.ones(20)
    ds_test = BaseDS()
    with pytest.raises(ValueError):
        ds_test.fit(X, y)
Example #2
0
def test_all_classifiers_agree():
    # 10 classifiers that return 1
    predictions = np.ones((1, 10))

    assert np.all(BaseDS._all_classifier_agree(predictions))
Example #3
0
def test_not_fitted_ds():
    query = np.array([[1.0, 1.0]])

    ds_test = BaseDS()
    with pytest.raises(NotFittedError):
        ds_test.predict(query)
Example #4
0
def test_valid_selection_mode(knn_method):
    with pytest.raises(ValueError):
        ds = BaseDS(create_pool_classifiers(), knn_classifier=knn_method)
        ds.fit(X_dsel_ex1, y_dsel_ex1)
Example #5
0
def test_string_selection_mode(create_X_y):
    X, y = create_X_y
    ds = BaseDS(knn_classifier="knn")
    ds.fit(X, y)
    assert (isinstance(ds.roc_algorithm_, KNeighborsClassifier))
Example #6
0
def test_check_safe_k_value(safe_k):
    X = np.random.rand(10, 2)
    y = np.ones(10)
    with pytest.raises(ValueError):
        ds_test = BaseDS(safe_k=safe_k)
        ds_test.fit(X, y)
Example #7
0
def test_valid_safe_k(k, safe_k):
    X = np.random.rand(10, 2)
    y = np.ones(10)
    with pytest.raises(ValueError):
        ds = BaseDS([create_base_classifier(1)], k=k, safe_k=safe_k)
        ds.fit(X, y)
Example #8
0
def test_input_shape_fit():
    X = X_dsel_ex1
    y = np.ones(20)
    ds_test = BaseDS(create_pool_classifiers())
    with pytest.raises(ValueError):
        ds_test.fit(X, y)
Example #9
0
def test_bad_input_X(X):
    ds_test = BaseDS(create_pool_classifiers())
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    with pytest.raises(ValueError):
        ds_test.predict(X)
Example #10
0
def test_different_input_shape():
    query = np.array([[1.0, 1.0, 2.0]])
    ds_test = BaseDS(create_pool_classifiers())
    ds_test.fit(X_dsel_ex1, y_dsel_ex1)
    with pytest.raises(ValueError):
        ds_test.predict(query)
Example #11
0
def test_not_fitted_ds():
    query = np.array([[1.0, 1.0]])

    ds_test = BaseDS(create_pool_classifiers())
    with pytest.raises(NotFittedError):
        ds_test.predict(query)
Example #12
0
def test_string_selection_mode():
    ds = BaseDS(create_pool_classifiers(), knn_classifier="knn")
    ds.fit(X_dsel_ex1, y_dsel_ex1)
    assert(isinstance(ds.roc_algorithm_, KNeighborsClassifier))
Example #13
0
def test_valid_selection_mode(knn_method, create_X_y):
    X, y = create_X_y
    with pytest.raises(ValueError):
        ds = BaseDS(knn_classifier=knn_method)
        ds.fit(X, y)
Example #14
0
def test_valid_safe_k(k, safe_k):
    X = np.random.rand(10, 2)
    y = np.ones(10)
    with pytest.raises(ValueError):
        ds = BaseDS(k=k, safe_k=safe_k)
        ds.fit(X, y)
Example #15
0
def test_not_all_classifiers_agree():
    # 10 classifiers that return 1, and one that returns 2
    predictions = np.ones((10, 11))
    predictions[:, -1] = 2

    assert not np.all(BaseDS._all_classifier_agree(predictions))
Example #16
0
def test_input_IH_rate(IH_rate):
    X = np.random.rand(10, 2)
    y = np.ones(10)
    with pytest.raises((ValueError, TypeError)):
        ds = BaseDS(create_pool_classifiers(), with_IH=True, IH_rate=IH_rate)
        ds.fit(X, y)
Example #17
0
def test_bad_input_X(X_test, create_X_y):
    X_train, y_train = create_X_y
    ds_test = BaseDS()
    ds_test.fit(X_train, y_train)
    with pytest.raises(ValueError):
        ds_test.predict(X_test)
Example #18
0
def test_pool_single_model(create_X_y):
    X, y = create_X_y
    pool = [create_base_classifier(return_value=0, return_prob=[0.9, 0.1])]
    ds_tst = BaseDS(pool_classifiers=pool)
    with pytest.raises(ValueError):
        ds_tst.fit(X, y)