Submit
Path:
~
/
/
opt
/
alt
/
python35
/
share
/
doc
/
alt-python35-scikit-learn-0.18.1
/
examples
/
cluster
/
File Content:
plot_affinity_propagation.py
""" ================================================= Demo of affinity propagation clustering algorithm ================================================= Reference: Brendan J. Frey and Delbert Dueck, "Clustering by Passing Messages Between Data Points", Science Feb. 2007 """ print(__doc__) from sklearn.cluster import AffinityPropagation from sklearn import metrics from sklearn.datasets.samples_generator import make_blobs ############################################################################## # Generate sample data centers = [[1, 1], [-1, -1], [1, -1]] X, labels_true = make_blobs(n_samples=300, centers=centers, cluster_std=0.5, random_state=0) ############################################################################## # Compute Affinity Propagation af = AffinityPropagation(preference=-50).fit(X) cluster_centers_indices = af.cluster_centers_indices_ labels = af.labels_ n_clusters_ = len(cluster_centers_indices) print('Estimated number of clusters: %d' % n_clusters_) print("Homogeneity: %0.3f" % metrics.homogeneity_score(labels_true, labels)) print("Completeness: %0.3f" % metrics.completeness_score(labels_true, labels)) print("V-measure: %0.3f" % metrics.v_measure_score(labels_true, labels)) print("Adjusted Rand Index: %0.3f" % metrics.adjusted_rand_score(labels_true, labels)) print("Adjusted Mutual Information: %0.3f" % metrics.adjusted_mutual_info_score(labels_true, labels)) print("Silhouette Coefficient: %0.3f" % metrics.silhouette_score(X, labels, metric='sqeuclidean')) ############################################################################## # Plot result import matplotlib.pyplot as plt from itertools import cycle plt.close('all') plt.figure(1) plt.clf() colors = cycle('bgrcmykbgrcmykbgrcmykbgrcmyk') for k, col in zip(range(n_clusters_), colors): class_members = labels == k cluster_center = X[cluster_centers_indices[k]] plt.plot(X[class_members, 0], X[class_members, 1], col + '.') plt.plot(cluster_center[0], cluster_center[1], 'o', markerfacecolor=col, markeredgecolor='k', markersize=14) for x in X[class_members]: plt.plot([cluster_center[0], x[0]], [cluster_center[1], x[1]], col) plt.title('Estimated number of clusters: %d' % n_clusters_) plt.show()
Submit
FILE
FOLDER
Name
Size
Permission
Action
README.txt
101 bytes
0644
plot_adjusted_for_chance_measures.py
4300 bytes
0644
plot_affinity_propagation.py
2304 bytes
0644
plot_agglomerative_clustering.py
2931 bytes
0644
plot_agglomerative_clustering_metrics.py
4492 bytes
0644
plot_birch_vs_minibatchkmeans.py
3694 bytes
0644
plot_cluster_comparison.py
4681 bytes
0644
plot_cluster_iris.py
2593 bytes
0644
plot_color_quantization.py
3444 bytes
0644
plot_dbscan.py
2479 bytes
0644
plot_dict_face_patches.py
2747 bytes
0644
plot_digits_agglomeration.py
1694 bytes
0644
plot_digits_linkage.py
2959 bytes
0644
plot_face_compress.py
2479 bytes
0644
plot_face_segmentation.py
2839 bytes
0644
plot_face_ward_segmentation.py
2460 bytes
0644
plot_feature_agglomeration_vs_univariate_selection.py
3903 bytes
0644
plot_kmeans_assumptions.py
2040 bytes
0644
plot_kmeans_digits.py
4524 bytes
0644
plot_kmeans_silhouette_analysis.py
5888 bytes
0644
plot_kmeans_stability_low_dim_dense.py
4324 bytes
0644
plot_mean_shift.py
1793 bytes
0644
plot_mini_batch_kmeans.py
4092 bytes
0644
plot_segmentation_toy.py
3522 bytes
0644
plot_ward_structured_vs_unstructured.py
3369 bytes
0644
N4ST4R_ID | Naxtarrr