<jupyter_start><jupyter_text>Dendrogram<jupyter_code>import scipy.cluster.hierarchy as sch
dendrogram = sch.dendrogram(sch.linkage(X, method = "ward"))
plt.xlabel("Customers")
plt.ylabel("Differences")
plt.title("Dendrogram")
plt.show()<jupyter_output><empty_output><jupyter_text>Fitting hierarchical clustering to the dataset<jupyter_code>from sklearn.cluster import AgglomerativeClustering
hc = AgglomerativeClustering(n_clusters = 5, affinity = "euclidean", linkage = "ward")
y_hc = hc.fit_predict(X)
sns.scatterplot(X[:, 0], X[:, 1], hue = y_hc)
plt.xlabel("Annual Income (k$)")
plt.ylabel("Spending Score")
plt.title("Clustering")
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup