Partition data into K clusters based on feature similarity.
Use Case: Customer segmentation, Recommendation Systems etc.
Algorithm Steps
Initialize K cluster centroids randomly.
Assign each data point to the nearest centroid to form clusters.
Update centroids by calculating the mean of points in each cluster.
Repeat 2nd & 3rd steps 2 and 3 until convergence.
K-means Concept Visually: Step 1
K-means Algorithm: Initialization.
K-means Concept Visually: Step 2
K-means Algorithm: Centroid Initialization.
K-means Concept Visually: Step 3
K-means Algorithm: Member Assignment.
K-means Concept Visually: Step 4
K-means Algorithm: Centroid Update.
K-means Concept Visually: Step 5
K-means Algorithm: Re-assignment.
K-means Concept Visually: Step 6
K-means Algorithm: Calculate Centroid.
K-means Concept Visually: Step 7
K-means Algorithm: Re-assignment.
K-means Concept Visually: Step 8
K-means Algorithm: Convergence.
Choosing K with Elbow Method
Run K-means for a range of K values (e.g. 1 to 10).
Plot inertia/wcss (sum of squared distances to its centroid) vs K.
Look for "elbow" point where inertia reduction slows down.
Elbow point suggests optimal K balancing fit and complexity.
K-means Elbow Method: Plotting inertia vs K to find optimal number of clusters.
Practice QuestionsNot started
K-means Clustering
Question 1 of 1
Using Credit Card Customer Data, perform K-means clustering:
1. Load and explore the dataset.
2. Perform necessary cleaning (missing, duplicate values).
3. Perform feature scaling and encoding if required.
4. Train K-means model for K=1 to 10 and plot the Elbow curve.
5. Select optimal K and assign cluster labels to customers.
Your privacy choices
Optional website statistics, Google Analytics/Clarity and advertising (Meta/Google) help measure and support this free site. Your choice does not limit learning. Privacy policy.
These services may use cookies and receive browsing and device information. Change your choice later from the Privacy Policy page.