Пример #1
0
def test_fit_predict_n_jobs_all(data_random):
    
    n_clusters = data_random['n_clusters']
    kmeans = MultiviewKMeans(n_clusters=n_clusters, n_jobs=-1)
    cluster_pred = kmeans.fit_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'])
Пример #2
0
def test_fit_predict_n_clusters():

    n_clusters = 3
    v1_data = np.array([[0, 0],[1, 0],[0, 1]])
    v2_data = np.array([[0, 0],[1, 0],[0, 1]])
    data = [v1_data, v2_data]
    kmeans = MultiviewKMeans(n_clusters=n_clusters)
    cluster_pred = kmeans.fit_predict(data)
    cluster_pred = list(set(cluster_pred))
    assert(len(cluster_pred) == n_clusters)
Пример #3
0
def test_fit_predict_init_random(data_random):
    
    n_clusters = data_random['n_clusters']
    init = 'random'
    kmeans = MultiviewKMeans(n_clusters=n_clusters, init='random')
    cluster_pred = kmeans.fit_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_fit_predict_patience(data_random):
    
    n_clusters = data_random['n_clusters']
    patience=10
    kmeans = MultiviewKMeans(n_clusters=n_clusters, patience=patience)
    cluster_pred = kmeans.fit_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'])
Пример #5
0
def test_fit_predict_max_iter(data_random):

    n_clusters = data_random['n_clusters']
    max_iter = 5
    kmeans = MultiviewKMeans(n_clusters=n_clusters, max_iter=max_iter)
    cluster_pred = kmeans.fit_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'])
Пример #6
0
def test_fit_predict_init_predefined():

    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, init=centroids)
    cluster_pred = kmeans.fit_predict(data)