Did you like this answer?
👍 0
👎 0
Let's solve **Question 4: Apply K-means algorithm (for K=2) for the table below.**
Given data:
| Instance | x | y |
|----------|-------|-------|
| 1 | 1.0 | 1.5 |
| 2 | 1.0 | 4.5 |
| 3 | 2.0 | 1.5 |
| 4 | 2.0 | 3.5 |
| 5 | 3.0 | 2.5 |
| 6 | 5.0 | 6.0 |
Let's walk through the steps of the **K-means algorithm with K=2**:
---
### **Step 1: Initialization**
Randomly choose two initial centroids. Let's pick:
- Centroid 1: Instance 1 (1.0, 1.5)
- Centroid 2: Instance 6 (5.0, 6.0)
---
### **Step 2: Assignment Step**
Calculate the Euclidean distance from each point to each centroid and assign each point to the nearest centroid.
#### **Instance 1 (1.0, 1.5):**
- To Centroid 1: distance = 0 (itself)
- To Centroid 2: sqrt((1-5)² + (1.5-6)²) = sqrt(16 + 20.25) = sqrt(36.25) ≈ 6.02
→ **Assign to Cluster 1**
#### **Instance 2 (1.0, 4.5):**
- To Centroid 1: sqrt((1-1)² + (4.5-1.5)²) = sqrt(0 + 9) = 3
- To Centroid 2: sqrt((1-5)² + (4.5-6)²) = sqrt(16 + 2.25) = sqrt(18.25) ≈ 4.27
→ **Assign to Cluster 1**
#### **Instance 3 (2.0, 1.5):**
- To Centroid 1: sqrt((2-1)² + (1.5-1.5)²) = sqrt(1 + 0) = 1
- To Centroid 2: sqrt((2-5)² + (1.5-6)²) = sqrt(9 + 20.25) = sqrt(29.25) ≈ 5.41
→ **Assign to Cluster 1**
#### **Instance 4 (2.0, 3.5):**
- To Centroid 1: sqrt((2-1)² + (3.5-1.5)²) = sqrt(1 + 4) = sqrt(5) ≈ 2.24
- To Centroid 2: sqrt((2-5)² + (3.5-6)²) = sqrt(9 + 6.25) = sqrt(15.25) ≈ 3.91
→ **Assign to Cluster 1**
#### **Instance 5 (3.0, 2.5):**
- To Centroid 1: sqrt((3-1)² + (2.5-1.5)²) = sqrt(4 + 1) = sqrt(5) ≈ 2.24
- To Centroid 2: sqrt((3-5)² + (2.5-6)²) = sqrt(4 + 12.25) = sqrt(16.25) ≈ 4.03
→ **Assign to Cluster 1**
#### **Instance 6 (5.0, 6.0):**
- To Centroid 1: sqrt((5-1)² + (6-1.5)²) = sqrt(16 + 20.25) = sqrt(36.25) ≈ 6.02
- To Centroid 2: 0
→ **Assign to Cluster 2**
---
### **Step 3: Update Step**
Calculate new centroids for each cluster.
#### **Cluster 1:** (Instances 1,2,3,4,5)
- Mean x: (1+1+2+2+3)/5 = 9/5 = 1.8
- Mean y: (1.5+4.5+1.5+3.5+2.5)/5 = 13.5/5 = 2.7
**New Centroid 1:** (1.8, 2.7)
#### **Cluster 2:** (Instance 6)
- Only one point: (5.0, 6.0)
**New Centroid 2:** (5.0, 6.0)
---
### **Step 4: Reassign Points**
Repeat the assignment step with the new centroids.
#### **Instance 1 (1.0, 1.5):**
- To (1.8,2.7): sqrt((1-1.8)^2 + (1.5-2.7)^2) = sqrt(0.64+1.44) = sqrt(2.08) ≈ 1.44
- To (5.0,6.0): ≈ 6.02 (as before)
→ **Cluster 1**
#### **Instance 2 (1.0, 4.5):**
- To (1.8,2.7): sqrt(0.64+3.24)=sqrt(3.88)≈1.97
- To (5.0,6.0): sqrt(16+2.25)=sqrt(18.25)≈4.27
→ **Cluster 1**
#### **Instance 3 (2.0, 1.5):**
- To (1.8,2.7): sqrt(0.04+1.44)=sqrt(1.48)≈1.22
- To (5.0,6.0): ≈ 5.41
→ **Cluster 1**
#### **Instance 4 (2.0, 3.5):**
- To (1.8,2.7): sqrt(0.04+0.64)=sqrt(0.68)≈0.82
- To (5.0,6.0): ≈ 3.91
→ **Cluster 1**
#### **Instance 5 (3.0, 2.5):**
- To (1.8,2.7): sqrt(1.44+0.04)=sqrt(1.48)≈1.22
- To (5.0,6.0): ≈ 4.03
→ **Cluster 1**
#### **Instance 6 (5.0, 6.0):**
- To (1.8,2.7): sqrt(10.24+10.89)=sqrt(21.13)≈4.6
- To (5.0,6.0): 0
→ **Cluster 2**
---
### **Step 5: Convergence Check**
The assignments did not change. The algorithm has converged.
---
## **Final Answer**
**Cluster 1 (Centroid at (1.8, 2.7)):**
- Instances 1, 2, 3, 4, 5
**Cluster 2 (Centroid at (5.0, 6.0)):**
- Instance 6
---
**Assignments:**
| Instance | Cluster |
|----------|---------|
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
| 6 | 2 |
---
If you need solutions for Q1, Q2, or Q3, let me know!