Mokani Aiml-8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Name Aakash Mokani

UID no. 2022300062

Experiment No. 8

Unsupervised Learning Algorithms

Problem Statement:

To perform clustering using K-means on the given dataset.

Sample dataset from kaggle(Iris dataset):

Dataset Link: Kaggle

Notebook Link: Colab


Code:

Selecting only the first two features for clustering and visualization:
Step 1: Define the number of clusters (k) and initialize random centroids for each cluster.

Step 2: Define the Euclidean distance function:


Step 3: Assign each point to the nearest cluster center:

Step 4: Update cluster centers to the mean of assigned points:

Now, clustering is completed.


Step 5: Predict the cluster for each data point in the dataframe:

Step 6: Run multiple iterations of step 3 and step 4 (assign and update) for all the data
points in the dataset.

it=5 Specifies the number of times we will iterate over the step 3 and 4. In a typical
K-means algorithm, we continue iterating until the cluster centers do not change
significantly (i.e., until convergence). Here, I have limited it to 5 iterations for simplicity.

Predicting clusters for final plot:


Step 7: Plot the final clusters with updated cluster centers:

Conclusion: This experiment with unsupervised learning algorithms provided


valuable insights into their functionality, especially the workings of the K-means
clustering algorithm. I applied this understanding to effectively cluster the well-
known iris dataset

You might also like