Aiml 8
Aiml 8
Experiment No. 8
Problem Statement:
Unsupervised learning is a machine learning approach that works with unlabeled data, meaning the data
lacks predefined categories or labels. The aim of unsupervised learning is to uncover patterns and
relationships within the data independently, without external guidance.
In this approach, the model's task is to group unclassified data by identifying similarities, differences, and
patterns without prior training on labeled data.
Unsupervised learning generally falls into two main categories: Clustering and Association.
Clustering is a common unsupervised learning technique that organizes similar data points into groups.
Clustering algorithms achieve this by iteratively moving data points closer to the center of their respective
clusters, creating groups where data points within the same group are more alike than those in other
groups. Clustering is essentially a way of organizing items based on their similarities and differences.
K-Means Clustering is a popular clustering algorithm used for dividing data points into a specified
number of clusters, represented by ‘K’. The algorithm follows these steps:
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 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.