This repository contains a Jupyter Notebook (K-Means-comparing-metrics-with-pca-2-unsupervised-machine-learning.ipynb
) that demonstrates the process of performing K-Means clustering on the Iris dataset using different distance metrics (Euclidean, Manhattan, Cosine) and evaluating the clustering results with Principal Component Analysis (PCA).
The analysis starts with importing the Iris dataset using the load_iris()
function from scikit-learn. Information about the dataset including feature names, target names, and data shape is displayed.
K-Means clustering is performed using scikit-learn's KMeans
class with 3 clusters. The cluster centers and labels are obtained.
Euclidean, Manhattan, and Cosine distances between data points and cluster centers are computed using scikit-learn's euclidean_distances
, manhattan_distances
, and cosine_distances
functions.
Principal Component Analysis (PCA) is applied to reduce the dimensionality of the dataset to 2 components.
Scatter plots are created to visualize the clustering results along with the distances using PCA. Each subplot represents a different distance metric (Euclidean, Manhattan, Cosine) with corresponding silhouette score displayed in the title.
An analysis is provided based on the scatter plots and silhouette scores for each distance metric. The correlation between distance metrics and principal component 1 is discussed, along with insights into clustering quality.
The conclusion summarizes the findings of the analysis, including the assessment of clustering quality for each distance metric and recommendations for further analysis.
To run the notebook locally, clone the repository and open the K-Means-comparing-metrics-with-pca.ipynb
file in Jupyter Notebook or JupyterLab.
- scikit-learn
- matplotlib