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)
def test_all_classifiers_agree(): # 10 classifiers that return 1 predictions = np.ones((1, 10)) assert np.all(BaseDS._all_classifier_agree(predictions))
def test_not_fitted_ds(): query = np.array([[1.0, 1.0]]) ds_test = BaseDS() with pytest.raises(NotFittedError): ds_test.predict(query)
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)
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))
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)
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)
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)
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)
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)
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)
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))
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)
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)
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))
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)
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)
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)