Example #1
0
def test_select():
    query = np.atleast_2d([1, -1])
    clustering_test = DESClustering(create_pool_classifiers() * 2, k=2)
    clustering_test.roc_algorithm.predict = MagicMock(return_value=[0])
    clustering_test.indices = np.array([[0, 2], [1, 4]])
    assert np.array_equal(clustering_test.select(query), [0, 2])

    clustering_test.roc_algorithm.predict = MagicMock(return_value=[1])
    assert np.array_equal(clustering_test.select(query), [1, 4])
Example #2
0
def test_select():
    query = np.atleast_2d([1, -1])
    clustering_test = DESClustering()

    clustering_test.clustering_ = KMeans()
    clustering_test.clustering_.predict = MagicMock(return_value=[0])
    clustering_test.indices_ = np.array([[0, 2], [1, 4]])
    assert np.array_equal(clustering_test.select(query), [[0, 2]])

    clustering_test.clustering_.predict = MagicMock(return_value=[1])
    assert np.array_equal(clustering_test.select(query), [[1, 4]])
Example #3
0
def test_classify_instance():
    query = np.atleast_2d([1, -1])
    clustering_test = DESClustering(create_pool_classifiers() * 4, k=2)
    clustering_test.select = MagicMock(return_value=[0, 1, 2, 3, 5, 6, 7, 9])

    predicted = clustering_test.classify_instance(query)
    assert predicted == 0
Example #4
0
def test_classify_with_ds_single_sample():
    query = np.ones(2)
    predictions = np.array([0, 1, 0])

    desknn_test = DESClustering(create_pool_classifiers())
    desknn_test.select = MagicMock(return_value=np.array([[0, 2]]))
    result = desknn_test.classify_with_ds(query, predictions)
    assert np.allclose(result, 0)
Example #5
0
def test_classify_instance():
    query = np.atleast_2d([1, -1])
    clustering_test = DESClustering(create_pool_classifiers() * 4, k=2)
    clustering_test.select = MagicMock(return_value=[0, 1, 2, 3, 5, 6, 7, 9])

    predictions = []
    for clf in clustering_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])

    predicted = clustering_test.classify_instance(query, np.array(predictions))
    assert predicted == 0
Example #6
0
def test_classify_instance(create_pool_classifiers):
    query = np.ones((1, 2))
    clustering_test = DESClustering(create_pool_classifiers * 4,
                                    clustering=KMeans(n_clusters=2))

    clustering_test.select = MagicMock(return_value=[0, 1, 2, 3, 5, 6, 7, 9])
    predictions = []
    for clf in clustering_test.pool_classifiers:
        predictions.append(clf.predict(query)[0])

    predicted = clustering_test.classify_with_ds(query, np.array(predictions))
    assert predicted == 0