0

I have this:

my result

And I want to have 25 clusters. So I used this:

from sklearn.cluster import AgglomerativeClustering
hc = AgglomerativeClustering(n_clusters = 25, affinity = 'euclidean', linkage = 'ward')
y_hc = hc.fit_predict(df)
df['class'] = y_hc

Now to show these clusters I used this code however in the labels it shows label count but I want to show the cluster lable

linkage_matrix = hierarchy.linkage(df.iloc[:, :-2], method='ward', metric='euclidean')

# Plot the dendrogram
plt.figure(figsize=(12, 6))

dendrogram = hierarchy.dendrogram(linkage_matrix,labels=df['cluster'].values,p=25,truncate_mode='lastp',leaf_font_size=10, leaf_rotation=90)
plt.xlabel('Genomes')
plt.ylabel('Euclidean distances')
plt.title(f'Hierarchical Clustering Dendrogram (method="ward")')
plt.show()

enter image description here

2
  • df is not defined. presumably a dataframe or some kind. Commented Dec 3, 2023 at 9:02
  • the question needs sufficient code for a minimal reproducible example Commented Dec 3, 2023 at 9:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.