Professional Documents
Culture Documents
import numpy as np
import pandas as pd
print()
digits = load_digits()
data = scale(digits.data)
labels = digits.target
sample_size = 300
Output:
labels.shape
Output: (1797, )
sse = {}
accuracy = []
sse[k] = kmeans.inertia_ # Inertia: Sum of distances of samples to their closest cluster center
labels_pred = kmeans.labels_
# print(labels_pred.shape)
accuracy.append(correct_labels/float(y.size))
get_cluster_metric(y, kmeans.labels_)
Visualisation:
#No. of clusters v/s SSE
plt.figure()
plt.plot(list(sse.keys()), list(sse.values()))
plt.xlabel("Number of cluster")
plt.ylabel("SSE")
plt.show()
plt.figure()
plt.plot(range(1, 20,1),accuracy)
plt.xlabel("Number of cluster")
plt.ylabel("accuracy")
plt.show()