diff --git a/Clustering/Hierarchical Clustering Algorithm example1.html b/Clustering/Hierarchical Clustering Algorithm example1.html new file mode 100644 index 0000000..9b6efdd --- /dev/null +++ b/Clustering/Hierarchical Clustering Algorithm example1.html @@ -0,0 +1,13281 @@ + + +
+ +%matplotlib inline
+import matplotlib.pyplot as plt
+import numpy as np
+
X = np.array(
+ [[7,8],[12,20],[17,19],[26,15],[32,37],[87,75],[73,85], [62,80],[73,60],[87,96],])
+labels = range(1, 11)
+plt.figure(figsize = (10, 7))
+plt.subplots_adjust(bottom = 0.1)
+plt.scatter(X[:,0],X[:,1], label = 'True Position')
+for label, x, y in zip(labels, X[:, 0], X[:, 1]):
+ plt.annotate(
+ label,xy = (x, y), xytext = (-3, 3),textcoords = 'offset points', ha = 'right', va = 'bottom')
+plt.show()
+
from scipy.cluster.hierarchy import dendrogram, linkage
+from matplotlib import pyplot as plt
+linked = linkage(X, 'single')
+labelList = range(1, 11)
+plt.figure(figsize = (10, 7))
+dendrogram(linked, orientation = 'top',labels = labelList,
+ distance_sort ='descending',show_leaf_counts = True)
+plt.show()
+
from sklearn.cluster import AgglomerativeClustering
+cluster = AgglomerativeClustering(n_clusters = 2, affinity = 'euclidean', linkage = 'ward')
+cluster.fit_predict(X)
+
plt.scatter(X[:,0],X[:,1], c = cluster.labels_, cmap = 'rainbow')
+
+
import matplotlib.pyplot as plt
+import pandas as pd
+%matplotlib inline
+import numpy as np
+from pandas import read_csv
+path = r"C:\Users\pshiv\Desktop\CSV files\pima-indians-diabetes.csv"
+data = read_csv(path)
+array = data.values
+X = array[:,0:8]
+Y = array[:,8]
+data.shape
+(768, 9)
+data.head()
+
patient_data = data.iloc[:, 3:5].values
+import scipy.cluster.hierarchy as shc
+plt.figure(figsize = (10, 7))
+plt.title("Patient Dendograms")
+dend = shc.dendrogram(shc.linkage(data, method = 'ward'))
+
from sklearn.cluster import AgglomerativeClustering
+cluster = AgglomerativeClustering(n_clusters = 4, affinity = 'euclidean', linkage = 'ward')
+cluster.fit_predict(patient_data)
+plt.figure(figsize = (10, 7))
+plt.scatter(patient_data[:,0], patient_data[:,1], c = cluster.labels_, cmap = 'rainbow')
+
+