Beispiel #1
0
def test_agglomerative_clustering_with_distance_threshold_edge_case(
        linkage, threshold, y_true):
    # test boundary case of distance_threshold matching the distance
    X = [[0], [1]]
    clusterer = AgglomerativeClustering(n_clusters=None,
                                        distance_threshold=threshold,
                                        linkage=linkage)
    y_pred = clusterer.fit_predict(X)
    assert adjusted_rand_score(y_true, y_pred) == 1
def test_agglomerative_clustering_with_distance_threshold_edge_case(
        linkage, threshold, y_true):
    # test boundary case of distance_threshold matching the distance
    X = [[0], [1]]
    clusterer = AgglomerativeClustering(
        n_clusters=None,
        distance_threshold=threshold,
        linkage=linkage)
    y_pred = clusterer.fit_predict(X)
    assert adjusted_rand_score(y_true, y_pred) == 1
Beispiel #3
0
def cluster_ari(y_true, y_pred):
    from sklearn.metrics.cluster.supervised import adjusted_rand_score
    return adjusted_rand_score(y_true, y_pred)
Beispiel #4
0
            TDS.insert(j,a)    #adding new SOM data for Training
            data_K.insert(j,K[j])  #clusters corresponding to new data for SOM Training
    data = np.array([])
    data=np.array(TDS)
    if not TDS:
        break  # If Training DataSet(TDS) is empty, no training takes place and training stops




for i in range(len(population)):
    file.write("chromosome {0} : ".format(i)+ str(population[i]))
    file.write("\n Objectives (Sil, PBM) : "+str(objectives[i]))
    file.write("\nCluster size{0} :".format(i)+str(K[i])+'\n')
    file.write("Predicted Label for {0}: ".format(i)+ str(Final_label[i]))
    ari=adjusted_rand_score(actual_label,Final_label[i])
    file.write("\n ARI Score {0} : ".format(i)+ str(ari))
    file.write("\nMinkowski score {0} : ".format(i)+str(cal_minkowski_score(actual_label, Final_label[i])))
    file.write("\n----------------------------------------------------------------------------------------------------------------------------\n")

print "Returned pop  : ",population
print "Objectives  : ",objectives
return_ss = [item[0] for item in objectives]
return_di = [item[1] for item in objectives]
print "PBM : ",return_di
print "SS  : ",return_ss
print "Clusters : ", K
print "Max PBM : ",max(return_di)
print "Max Silhouette score : ",max(return_ss)