[go: up one dir, main page]

0% found this document useful (0 votes)
2 views1 page

Hierachial Clustering - Ipynb - Colab

The document outlines a Python script that performs agglomerative clustering on the Iris dataset using Manhattan distance and complete linkage, resulting in three clusters with varying item counts. It also applies PCA to reduce the dataset to two dimensions for visualization. Finally, it generates a scatter plot to illustrate the clusters based on the PCA-transformed data.

Uploaded by

Perfect OK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Hierachial Clustering - Ipynb - Colab

The document outlines a Python script that performs agglomerative clustering on the Iris dataset using Manhattan distance and complete linkage, resulting in three clusters with varying item counts. It also applies PCA to reduce the dataset to two dimensions for visualization. Finally, it generates a scatter plot to illustrate the clusters based on the PCA-transformed data.

Uploaded by

Perfect OK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

from sklearn.

cluster import AgglomerativeClustering


from sklearn.datasets import load_iris

iris = load_iris()
X = iris.data
hc = AgglomerativeClustering(n_clusters=3,metric="manhattan",linkage='complete')

label = hc.fit_predict(X)
print(f"No of items in first cluster:{list(label).count(0)}")
print(f"No of items in second cluster:{list(label).count(1)}")
print(f"No of items in third cluster:{list(label).count(2)}")

No of items in first cluster:66


No of items in second cluster:34
No of items in third cluster:50

from sklearn.decomposition import PCA

pca = PCA(n_components=2)
iris_pca = pca.fit_transform(iris.data)

import matplotlib.pyplot as plt

plt.figure(figsize=(8, 6))
plt.scatter(iris_pca[:, 0], iris_pca[:, 1], c=label, cmap='viridis')
plt.xlabel('Size of Sepal')
plt.ylabel('Size of Petal')
plt.title('PCA of Iris Dataset with K-Means Clusters')
plt.colorbar(label='Cluster Label')
plt.show()

You might also like