def test_obvious_clustering():
    random = np.random.RandomState(0)
    X = random.randn(40, 2)
    X[20:] += 5

    k1 = _MiniBatchKMedoids(n_clusters=2, max_iter=5, random_state=0, batch_size=20).fit(X)
    k2 = _KMedoids(n_clusters=2, n_passes=10).fit(X)

    assert (np.all(k1.labels_ == k2.labels_) or
            np.all(k1.labels_ == np.logical_not(k2.labels_)))
示例#2
0
def test_inertia():
    random = np.random.RandomState(0)
    X = random.randn(10, 2)

    for km in (_KMedoids(n_clusters=3,
                         n_passes=5), _MiniBatchKMedoids(n_clusters=3)):
        km.fit(X)
        inertia = 0
        for i in range(len(X)):
            inertia += euclidean(X[km.cluster_ids_[km.labels_[i]]], X[i])

        np.testing.assert_almost_equal(inertia, km.inertia_)
def test_inertia():
    random = np.random.RandomState(0)
    X = random.randn(10, 2)

    for km in (_KMedoids(n_clusters=3, n_passes=5),
               _MiniBatchKMedoids(n_clusters=3)):
        km.fit(X)
        inertia = 0
        for i in range(len(X)):
            inertia += euclidean(X[km.cluster_ids_[km.labels_[i]]], X[i])

        np.testing.assert_almost_equal(inertia, km.inertia_)
示例#4
0
def test_obvious_clustering():
    random = np.random.RandomState(0)
    X = random.randn(40, 2)
    X[20:] += 5

    k1 = _MiniBatchKMedoids(n_clusters=2,
                            max_iter=5,
                            random_state=0,
                            batch_size=20).fit(X)
    k2 = _KMedoids(n_clusters=2, n_passes=10).fit(X)

    assert (np.all(k1.labels_ == k2.labels_)
            or np.all(k1.labels_ == np.logical_not(k2.labels_)))
示例#5
0
 def minimedoid():
     return _MiniBatchKMedoids(metric='asdf').fit(np.zeros((10, 2)))
def test_4():
    assert_raises(ValueError, lambda: _MiniBatchKMedoids(metric='sdf').fit(np.zeros((10,2))))
    assert_raises(ValueError, lambda: _KMedoids(metric='sdf').fit(np.zeros((10,2))))
示例#7
0
def test_4():
    assert_raises(
        ValueError,
        lambda: _MiniBatchKMedoids(metric='sdf').fit(np.zeros((10, 2))))
    assert_raises(ValueError,
                  lambda: _KMedoids(metric='sdf').fit(np.zeros((10, 2))))
示例#8
0
 def minimedoid():
     return _MiniBatchKMedoids(metric='asdf').fit(np.zeros((10, 2)))