コード例 #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_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]