Comprehensive Guide to K-Means Clustering in Machine Learning for Mechanical Engineering Students
Detailed step-by-step K-Means clustering problems and solutions using Euclidean distance, centroids, and iterations for mechanical engineering applications in AI and ML.
Comprehensive Guide to K-Means Clustering in Machine Learning for Mechanical Engineering Students
1.
Sanjivani Rural EducationSociety’s
Sanjivani College of Engineering, Kopargaon-423603
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Mechanical Engineering
Subject : Foundations of AI and ML
Class : T.Y. Mechanical
Subject Code : PEME 312D
Unit 3 : Fundamentals of Machine Learning
By
V. P. Bhaurkar
Department of Mechanical Engineering
2025 – 26 (sem – 6)
2.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem 1
A set of machine temperature readings are given
as: 40°C, 42°C, 80°C, 82°C.
Cluster these data points into K = 2 clusters
using basic K-Means logic.
Given Data:
Data points: {40, 42, 80, 82}, K = 2
Step-by-Step Solution:
Step 1: Initialize clusters
Since data is clearly separated, assume initial
grouping:
Cluster 1 → {40, 42}
Cluster 2 → {80, 82}
Problem Solving
Step 2: Calculate centroids
Cluster 1 centroid:
= (40 + 42) / 2 = 41
Cluster 2 centroid:
= (80 + 82) / 2 = 81
Step 3: Check reassignment
•40 and 42 are closer to 41
•80 and 82 are closer to 81
No change → clustering stable
Final Answer:
Cluster 1 → {40, 42}, Centroid = 41
Cluster 2 → {80, 82}, Centroid = 81
3.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem 2
Cluster the following points into K = 2 clusters
using K-Means algorithm:
Points: A(1,1), B(2,1), C(8,8), D(9,8)
Given Data:
1. Number of clusters: K = 2
2. Points: (1,1), (2,1), (8,8), (9,8)
Step 1: Initialize Centroids
Assume initial centroids (random selection):
C1 = (1,1)
C2 = (8,8)
Problem Solving
Step 2: Calculate Distance of Each
Point from Centroids
We use Euclidean distance:
Distance of Point A (1,1)
From C1:
= √[(1−1)² + (1−1)²]
= √[0 + 0] = 0
From C2:
= √[(8−1)² + (8−1)²]
= √[49 + 49] = √98 ≈ 9.9
A belongs to Cluster 1
4.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Distance of Point B (2,1)
From C1:
= √[(2−1)² + (1−1)²]
= √[1 + 0] = 1
From C2:
= √[(8−2)² + (8−1)²]
= √[36 + 49] = √85 ≈ 9.22
B belongs to Cluster 1
Problem Solving
Distance of Point C (8,8)
From C1:
= √[(8−1)² + (8−1)²]
= √[49 + 49] = √98 ≈ 9.9
From C2:
= √[(8−8)² + (8−8)²]
= √[0 + 0] = 0
C belongs to Cluster 2
5.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Distance of Point D (9,8)
From C1:
= √[(9−1)² + (8−1)²]
= √[64 + 49] = √113 ≈ 10.63
From C2:
= √[(9−8)² + (8−8)²]
= √[1 + 0] = 1
D belongs to Cluster 2
Problem Solving
Step 3: Form Clusters
Cluster 1 → A(1,1), B(2,1)
Cluster 2 → C(8,8), D(9,8)
6.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Step 4: Calculate New Centroids
New Centroid of Cluster 1
Formula:
For points (1,1), (2,1):
x-coordinate:
= (1 + 2) / 2 = 1.5
y-coordinate:
= (1 + 1) / 2 = 1
New C1 = (1.5, 1)
Problem Solving
New Centroid of Cluster 2
For points (8,8), (9,8):
x-coordinate:
= (8 + 9) / 2 = 8.5
y-coordinate:
= (8 + 8) / 2 = 8
New C2 = (8.5, 8)
7.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Step 5: Check for Reassignment
Now we again check distances (quick logic):
A & B are still closer to (1.5,1)
C & D are still closer to (8.5,8)
No change → convergence achieved
Problem Solving
Final Answer:
Cluster 1 → {(1,1), (2,1)}
Centroid = (1.5, 1)
Cluster 2 → {(8,8), (9,8)}
Centroid = (8.5, 8)
8.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem 3
Cluster the following machine data into K =
2 clusters using K-Means:
Points:
(40,2), (42,3), (85,9), (88,10)
Given Data:
K = 2
Points:
M1(40,2), M2(42,3), M3(85,9), M4(88,10)
Step 1: Initialize Centroids
Assume:
C1 = (40,2), C2 = (85,9)
Problem Solving
Step 2: Distance Calculation
Table
We use:
9.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem Solving
Step 2: Distance Calculation Table
We use:
Point d from C1 (40,2) d from C2 (85,9) Cluster
(40,2) 0 √[(45²+7²)=2024] ≈ 45 C1
(42,3) √[(2²+1²)=5] ≈ 2.24 √[(43²+6²)=1905] ≈ 43.64 C1
(85,9) ≈ 45 0 C2
(88,10) √[(48²+8²)=2368] ≈ 48.66 √[(3²+1²)=10] ≈ 3.16 C2
10.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem Solving
Step 3: Form Clusters
Cluster 1 → (40,2), (42,3)
Cluster 2 → (85,9), (88,10)
Step 4: Calculate New Centroids
Cluster 1:
New C1 = (41, 2.5)
Cluster 2:
New C2 = (86.5, 9.5)
Step 5: Recheck Assignment
Distances will still keep points in same
cluster → stable
11.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem Solving
Final Answer:
Cluster 1 → {(40,2), (42,3)} → Centroid (41, 2.5)
Cluster 2 → {(85,9), (88,10)} → Centroid (86.5, 9.5)
12.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem Solving
Problem 4
A data related to vehicle sales is given
below. Cluster this data. Assume K=2.
(20,80), (22,85), (10,150), (12,160)
13.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem Solving
Problem 5
A quality control engineer is analyzing the vibration characteristics of four different bearings operating
under varying load conditions. Each bearing is characterized by two parameters:
X: Vibration amplitude (in microns, μm)
Y: Operating temperature (in °C)
The data points for four bearings are given in table.
The engineer wants to group these bearings into K = 2 clusters
based on their vibration-temperature characteristics to identify
which bearings are operating under normal conditions versus
stress conditions.
1. Perform TWO complete iterations of the K-means algorithm. For each iteration, show: Assignment of each data point
to the nearest centroid (using Euclidean distance)
2. Recalculation of new centroids
3. Based on your clustering result, interpret which bearings are operating under normal conditions and which are under
stress conditions. Justify your answer.
4. If a new bearing with vibration 15 μm and temperature 65°C is introduced, predict which cluster it would belong to
based on the final centroids.
Bearing Vibration Temperature
B1 5 45
B2 7 48
B3 25 85
B4 28 90
14.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem Solving
Problem 5
Solution:
Part (a): Initialization
Given data points:
B1 = (5, 45)
B2 = (7, 48)
B3 = (25, 85)
B4 = (28, 90)
Initial centroids:
C₁ = B1 = (5, 45)
C₂ = B4 = (28, 90)
Part (b): Iteration 1
Step 1: Calculate distances from each point to
centroids, Distance formula: Euclidean distance =
Bearing Vibration Temperature
B1 5 45
B2 7 48
B3 25 85
B4 28 90
For B1 (5, 45):
Distance to C₁ (5, 45):
Distance to C₂ (28, 90):
Remark: B1 → C₁ (since 0 < 50.54)
15.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem Solving
Problem 5
Solution:
For B2 (7, 48):
Distance to C₁ (5, 45):
Distance to C₂ (28, 90):
Note: Next steps to practice for students
Bearing Vibration Temperature
B1 5 45
B2 7 48
B3 25 85
B4 28 90
16.
V. P. BhaurkarAI ML (T. Y. Mechanical)
Problem Solving
Problem 6
Apply K-Means clustering (K = 2) on the following mixed data:
Points: A(2,2), B(3,3), C(6,5), D(8,7), E(9,8), F(5,4). Perform iterations until convergence.
Given Data:
K = 2
Points:
(2,2), (3,3), (6,5), (8,7), (9,8), (5,4)
Iteration 1
Step 1: Initial Centroids
Assume:
C1 = (2,2)
C2 = (8,7)
Step 2: Distance Table
Step 3: Clusters
C1 → (2,2), (3,3), (5,4), C2 → (6,5), (8,7), (9,8)
Point d from C1 (2,2) d from C2 (8,7) Cluster
(2,2) 0 √[(6²+5²)=61] ≈ 7.81 C1
(3,3) √2 ≈ 1.41 √[(5²+4²)=41] ≈ 6.4 C1
(6,5) √[(4²+3²)=25] = 5 √[(2²+2²)=8] ≈ 2.82 C2
(8,7) √61 ≈ 7.81 0 C2
(9,8) √[(7²+6²)=85] ≈ 9.22 √2 ≈ 1.41 C2
(5,4) √[(3²+2²)=13] ≈ 3.6 √[(3²+3²)=18] ≈ 4.24 C1
Step 4: New Centroids
Cluster 1: x = (2+3+5)/3 = 3.33
y = (2+3+4)/3 = 3, C1 = (3.33, 3)
Cluster 2: x = (6+8+9)/3 = 7.67, y = (5+7+8)/3 = 6.67
C2 = (7.67, 6.67)