October 2018
Intermediate to advanced
172 pages
4h 6m
English
Now that you have learned how hierarchical clustering works, we can implement this concept. In order to create a hierarchical cluster, we use the following code:
from scipy.cluster.hierarchy import linkagefrom scipy.cluster.hierarchy import dendrogramimport numpy as npimport matplotlib.pyplot as plt #Creating an array of 4 featuresarray = np.array([[1,2,3,4], [5,6,7,8], [2,3,4,5], [5,6,4,3]])feature_names = ['a', 'b', 'c', 'd']#Creating clustersclusters = linkage(array, method = 'complete')#Creating a dendrogramdendrogram(clusters, labels = feature_names, leaf_rotation = 90)plt.show()
The preceding code results in a dendrogram, as illustrated in the following diagram:
In the preceding code, ...
Read now
Unlock full access