コード例 #1
0
def test_predict_no_centroids1():
    with pytest.raises(AttributeError):
        kmeans = MultiviewKMeans()
        kmeans.centroids_ = [None, None]
        view1 = np.random.random((10, 11))
        view2 = np.random.random((10, 10))
        kmeans.predict([view1, view2])
コード例 #2
0
def test_predict_no_centroids2():
    kmeans = MultiviewKMeans()

    with pytest.raises(ConvergenceWarning):
        view1 = np.array([[0, 1], [1, 0]])
        view2 = np.array([[1, 0], [0, 1]])
        v1_centroids = np.array([[0, 1], [1, 0]])
        v2_centroids = np.array([[0, 1], [1, 0]])
        centroids = [v1_centroids, v2_centroids]
        kmeans._final_centroids([view1, view2], centroids)

    with pytest.raises(AttributeError):
        kmeans.predict([view1, view2])
コード例 #3
0
def test_predict_random_small(data_random):

    kmeans = MultiviewKMeans()
    input_data = [
        data_random['fit_data'][0][:2], data_random['fit_data'][1][:2]
    ]
    kmeans.fit(input_data)
    cluster_pred = kmeans.predict(data_random['test_data'])

    assert (data_random['n_test'] == cluster_pred.shape[0])

    for cl in cluster_pred:
        assert (cl >= 0 and cl < data_random['n_clusters'])
コード例 #4
0
def test_predict_deterministic():

    n_clusters = 2
    v1_centroid = np.array([[0, 0], [1, 1]])
    v2_centroid = np.array([[0, 0], [1, 1]])
    centroids = [v1_centroid, v2_centroid]
    v1_data = np.array([[0, 0], [0.3, 0.2], [0.5, 0.5], [0.7, 0.7], [1, 1]])
    v2_data = np.array([[0, 0], [0.2, 0.4], [0.5, 0.5], [0.4, 0.7], [1, 1]])
    data = [v1_data, v2_data]
    kmeans = MultiviewKMeans(n_clusters=n_clusters)
    kmeans.centroids_ = centroids
    cluster_pred = kmeans.predict(data)
    true_clusters = [0, 0, 0, 1, 1]

    for ind in range(len(true_clusters)):
        assert cluster_pred[ind] == true_clusters[ind]
コード例 #5
0
def test_predict_not_fit():
    with pytest.raises(NotFittedError):
        kmeans = MultiviewKMeans()
        view1 = np.random.random((10, 11))
        view2 = np.random.random((10, 10))
        kmeans.predict([view1, view2])