-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagl.py
More file actions
26 lines (22 loc) · 753 Bytes
/
agl.py
File metadata and controls
26 lines (22 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import AgglomerativeClustering
from scipy.cluster.hierarchy import dendrogram, linkage
# Height and Weight of students
x = np.array([[150, 50],[152, 52],[155, 54],[170, 70],[172, 72],[175, 75]])
# linked = linkage(x, method='ward')
# plt.figure(figsize=(6,4))
# plt.subplot(1,2,1)
# dendrogram(linked)
# plt.title("Dendrogram")
# plt.xlabel("Students")
# plt.ylabel("Distance")
model = AgglomerativeClustering(n_clusters=2, linkage='ward')
labels = model.fit_predict(x)
print("Cluster Labels:", labels)
# plt.subplot(1,2,2)
plt.scatter(x[:,0], x[:,1], c=labels)
plt.xlabel("Height")
plt.ylabel("Weight")
plt.title("Agglomerative Clustering")
plt.show()