-
Notifications
You must be signed in to change notification settings - Fork 1
/
agglomerative.py
31 lines (26 loc) · 970 Bytes
/
agglomerative.py
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
27
28
29
30
31
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# %matplotlib inline
import scipy.cluster.hierarchy as shc
from scipy.spatial.distance import squareform, pdist
a = [0.4,0.22,0.35,0.26,0.08,0.45]
b = [0.53,0.38,0.32,0.19,0.41,0.30]
point = ['P1','P2','P3','P4','P5','P6']
data = pd.DataFrame({'Point':point,'a':np.round(a,2),'b':np.round(b,2)})
data = data.set_index('Point')
print(data)
plt.figure(figsize=(8,5))
plt.scatter(data['a'],data['b'],c='r',marker="*")
plt.xlabel('Column a')
plt.ylabel('Column b')
plt.title('Scatter Plot of x and y')
for j in data.itertuples():
plt.annotate(j.Index, (j.a, j.b), fontsize=15)
plt.show()
dist = pd.DataFrame(squareform(pdist(data[['a','b']]),'euclidean'),columns=data.index.values,index=data.index.values)
print(dist)
plt.figure(figsize=(12,5))
plt.title("Dendogram")
dend = shc.dendrogram(shc.linkage(data[['a','b']],method='single'),labels=data.index)
plt.show()