Skip to content

Instantly share code, notes, and snippets.

@orico
Last active April 24, 2018 07:00
Show Gist options
  • Save orico/754b2ab5e126438046cc7874ba84ad95 to your computer and use it in GitHub Desktop.
Save orico/754b2ab5e126438046cc7874ba84ad95 to your computer and use it in GitHub Desktop.
PCAAE-KMEANS
labels_true = y
titles = ['PCA', 'Linear AE', 'Sigmoid AE', 'Relu AE']
for n_clusters_ in [2,3]:
estimators = [('PCA' , KMeans(n_clusters=n_clusters_), pca_transformed),
('AE linear' , KMeans(n_clusters=n_clusters_), encoded_data),
('AE sigmoid' , KMeans(n_clusters=n_clusters_), encoded_data2),
('AE relu', KMeans(n_clusters=n_clusters_), encoded_data3)]
print(type(y))
print('Number of clusters: %d' % n_clusters_)
for name, est, data in estimators:
X = data
est.fit(X)
labels = est.labels_
print(name,':')
print(labels[:])
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))
print()
print()
print('----------------------------------------------------------------------------------')
print()
# Number of clusters: 2
# PCA :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0]
# Homogeneity: 0.579
# Completeness: 1.000
# V-measure: 0.734
# Adjusted Rand Index: 0.568
# Adjusted Mutual Information: 0.577
# Silhouette Coefficient: 0.629
# AE linear :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0]
# Homogeneity: 0.579
# Completeness: 1.000
# V-measure: 0.734
# Adjusted Rand Index: 0.568
# Adjusted Mutual Information: 0.577
# Silhouette Coefficient: 0.647
# AE sigmoid :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0]
# Homogeneity: 0.579
# Completeness: 1.000
# V-measure: 0.734
# Adjusted Rand Index: 0.568
# Adjusted Mutual Information: 0.577
# Silhouette Coefficient: 0.650
# AE relu :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0]
# Homogeneity: 0.579
# Completeness: 1.000
# V-measure: 0.734
# Adjusted Rand Index: 0.568
# Adjusted Mutual Information: 0.577
# Silhouette Coefficient: 0.752
# ----------------------------------------------------------------------------------
# Number of clusters: 3
# PCA :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 1 1 1 1 1 1 1 1 1 2 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
# 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 2 2 2 2 0 2 2 2 2
# 2 2 0 2 2 2 2 2 0 2 0 2 0 2 2 0 0 2 2 2 2 2 0 0 2 2 2 0 2 2 2 0 2 2 2 0 2
# 2 0]
# Homogeneity: 0.736
# Completeness: 0.747
# V-measure: 0.742
# Adjusted Rand Index: 0.716
# Adjusted Mutual Information: 0.733
# Silhouette Coefficient: 0.504
# AE linear :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 0 0 0 2 0 0 0 0 0 0 0 0 2 0 0 0 0 2 0 0 0
# 0 2 2 2 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 2 2 2 2 0 2 2 2 2
# 2 2 0 0 2 2 2 2 0 2 0 2 0 2 2 0 2 2 2 2 2 2 0 0 2 2 2 0 2 2 2 0 2 2 2 0 2
# 2 0]
# Homogeneity: 0.659
# Completeness: 0.660
# V-measure: 0.659
# Adjusted Rand Index: 0.620
# Adjusted Mutual Information: 0.655
# Silhouette Coefficient: 0.508
# AE sigmoid :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 2 0 2 0 2 0 2 2 2 2 2 2 0 2 2 2 2 0 2 2 2
# 0 0 0 0 2 2 2 2 2 2 2 0 0 2 2 2 2 0 2 2 2 2 2 2 2 2 0 2 0 0 0 0 2 0 0 0 0
# 0 0 2 2 0 0 0 0 2 0 2 0 2 0 0 2 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0
# 0 2]
# Homogeneity: 0.646
# Completeness: 0.647
# V-measure: 0.647
# Adjusted Rand Index: 0.601
# Adjusted Mutual Information: 0.642
# Silhouette Coefficient: 0.556
# AE relu :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 0 1 1 1 1 1 1 1 1 2 2 2 0 2 0 2 0 2 0 0 0 0 0 0 2 0 0 2 0 2 0 2 0
# 2 2 2 2 0 0 0 0 0 2 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 0 2 2 2 2
# 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
# 2 2]
# Homogeneity: 0.699
# Completeness: 0.718
# V-measure: 0.708
# Adjusted Rand Index: 0.676
# Adjusted Mutual Information: 0.695
# Silhouette Coefficient: 0.550
# ----------------------------------------------------------------------------------
# PCA :
# [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
# 1 1 1 1 1 1 1 1 1 1 1 1 1 0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