Esempio n. 1
0
def test_predict():
    """Test predict."""
    clusterer = BlockClustering(blocking="precomputed",
                                base_estimator=MiniBatchKMeans(n_clusters=2))
    clusterer.fit(X, blocks=(y <= 1))
    pred = clusterer.predict(X, blocks=(y <= 1))
    assert_array_equal([25, 25, 25, 25], np.bincount(clusterer.labels_))

    pred = clusterer.predict(X, blocks=10 * np.ones(len(X)))
    assert_array_equal(-np.ones(len(X)), pred)
Esempio n. 2
0
def test_predict():
    """Test predict."""
    clusterer = BlockClustering(blocking="precomputed",
                                base_estimator=MiniBatchKMeans(n_clusters=2))
    clusterer.fit(X, blocks=(y <= 1))
    pred = clusterer.predict(X, blocks=(y <= 1))
    assert_array_equal([25, 25, 25, 25], np.bincount(clusterer.labels_))

    pred = clusterer.predict(X, blocks=10 * np.ones(len(X)))
    assert_array_equal(-np.ones(len(X)), pred)
Esempio n. 3
0
def test_validation():
    """Test the validation of hyper-parameters and input data."""
    with pytest.raises(ValueError):
        clusterer = BlockClustering(
            blocking="foobar", base_estimator=MiniBatchKMeans(n_clusters=2))
        clusterer.fit(X)

    with pytest.raises(ValueError):
        clusterer = BlockClustering(
            blocking="precomputed",
            base_estimator=MiniBatchKMeans(n_clusters=2))
        clusterer.fit(X)

    with pytest.raises(ValueError):
        clusterer = BlockClustering(
            blocking="precomputed",
            base_estimator=MiniBatchKMeans(n_clusters=2))
        clusterer.fit(X, blocks=(y <= 1))
        clusterer.predict(X)
Esempio n. 4
0
def test_validation():
    """Test the validation of hyper-parameters and input data."""
    with pytest.raises(ValueError):
        clusterer = BlockClustering(
            blocking="foobar",
            base_estimator=MiniBatchKMeans(n_clusters=2))
        clusterer.fit(X)

    with pytest.raises(ValueError):
        clusterer = BlockClustering(
            blocking="precomputed",
            base_estimator=MiniBatchKMeans(n_clusters=2))
        clusterer.fit(X)

    with pytest.raises(ValueError):
        clusterer = BlockClustering(
            blocking="precomputed",
            base_estimator=MiniBatchKMeans(n_clusters=2))
        clusterer.fit(X, blocks=(y <= 1))
        clusterer.predict(X)
Esempio n. 5
0
def test_partial_fit():
    """Test partial_fit."""
    blocks = (y <= 1)

    clusterer1 = BlockClustering(blocking="precomputed",
                                 base_estimator=MiniBatchKMeans(n_clusters=2))
    clusterer1.partial_fit(X[y <= 1], blocks=blocks[y <= 1])
    assert_equal(len(clusterer1.clusterers_), 1)
    clusterer1.partial_fit(X[y > 1], blocks=blocks[y > 1])
    assert_equal(len(clusterer1.clusterers_), 2)

    clusterer2 = BlockClustering(blocking="precomputed",
                                 base_estimator=MiniBatchKMeans(n_clusters=2))
    clusterer2.fit(X, blocks=blocks)

    c1 = clusterer1.predict(X, blocks=blocks)
    c2 = clusterer2.labels_

    assert_equal(paired_f_score(c1, c2), 1.0)
Esempio n. 6
0
def test_partial_fit():
    """Test partial_fit."""
    blocks = (y <= 1)

    clusterer1 = BlockClustering(blocking="precomputed",
                                 base_estimator=MiniBatchKMeans(n_clusters=2))
    clusterer1.partial_fit(X[y <= 1], blocks=blocks[y <= 1])
    assert_equal(len(clusterer1.clusterers_), 1)
    clusterer1.partial_fit(X[y > 1], blocks=blocks[y > 1])
    assert_equal(len(clusterer1.clusterers_), 2)

    clusterer2 = BlockClustering(blocking="precomputed",
                                 base_estimator=MiniBatchKMeans(n_clusters=2))
    clusterer2.fit(X, blocks=blocks)

    c1 = clusterer1.predict(X, blocks=blocks)
    c2 = clusterer2.labels_

    assert_equal(paired_f_score(c1, c2), 1.0)
Esempio n. 7
0
def test_single_signature(n_jobs):
    """Test clustering of a  single signature."""
    import numbers
    clusterer = BlockClustering(base_estimator=MiniBatchKMeans(n_clusters=2))
    clusterer.fit(np.array([X[0]]))
    assert isinstance(clusterer.predict(X[0])[0], numbers.Integral)
Esempio n. 8
0
def test_single_signature(n_jobs):
    """Test clustering of a  single signature."""
    import numbers
    clusterer = BlockClustering(base_estimator=MiniBatchKMeans(n_clusters=2))
    clusterer.fit(np.array([X[0]]))
    assert isinstance(clusterer.predict(X[0])[0], numbers.Integral)