Apply Weighted KNN Algorithm using the given dataset to classify the test set data (7.6, 60, 8) where k = 3
Answer:-
Let’s apply the Weighted K-Nearest Neighbors (KNN) algorithm step-by-step to classify the test data point (CGPA = 7.6, Assessment = 60, Project Submitted = 8) using the given dataset and k=3k = 3.
Step 1: Training Data
S.No | CGPA | Assessment | Project | Result |
---|---|---|---|---|
1 | 9.2 | 85 | 8 | Pass |
2 | 8.0 | 80 | 7 | Pass |
3 | 8.5 | 81 | 8 | Pass |
4 | 6.0 | 45 | 5 | Fail |
5 | 6.5 | 50 | 4 | Fail |
6 | 8.2 | 72 | 7 | Pass |
7 | 5.8 | 38 | 5 | Fail |
8 | 8.9 | 91 | 9 | Pass |
Step 2: Test Point
Test instance:
(x1,x2,x3)=(7.6, 60, 8)(x_1, x_2, x_3) = (7.6,\ 60,\ 8)
Step 3: Distance Calculation (Euclidean Distance)
Distance formula: d=(x1−xi)2+(x2−yi)2+(x3−zi)2d = \sqrt{(x_1 – x_i)^2 + (x_2 – y_i)^2 + (x_3 – z_i)^2}
We’ll compute distance from test point to each record:
S.No | CGPA | Assess | Project | Result | Distance |
---|---|---|---|---|---|
1 | 9.2 | 85 | 8 | Pass | √((7.6−9.2)² + (60−85)² + (8−8)²) = √((−1.6)² + (−25)²) = √(2.56 + 625) = √627.56 ≈ 25.05 |
2 | 8.0 | 80 | 7 | Pass | √((−0.4)² + (−20)² + 1²) = √(0.16 + 400 + 1) = √401.16 ≈ 20.02 |
3 | 8.5 | 81 | 8 | Pass | √((−0.9)² + (−21)²) = √(0.81 + 441) = √441.81 ≈ 21.02 |
4 | 6.0 | 45 | 5 | Fail | √((1.6)² + (15)² + 3²) = √(2.56 + 225 + 9) = √236.56 ≈ 15.38 |
5 | 6.5 | 50 | 4 | Fail | √((1.1)² + 10² + 4²) = √(1.21 + 100 + 16) = √117.21 ≈ 10.82 |
6 | 8.2 | 72 | 7 | Pass | √((−0.6)² + (−12)² + 1²) = √(0.36 + 144 + 1) = √145.36 ≈ 12.05 |
7 | 5.8 | 38 | 5 | Fail | √((1.8)² + 22² + 3²) = √(3.24 + 484 + 9) = √496.24 ≈ 22.28 |
8 | 8.9 | 91 | 9 | Pass | √((−1.3)² + (−31)² + (−1)²) = √(1.69 + 961 + 1) = √963.69 ≈ 31.03 |
Step 4: Select K = 3 Nearest Neighbors
Sort by distance:
S.No | Result | Distance |
---|---|---|
5 | Fail | 10.82 |
6 | Pass | 12.05 |
4 | Fail | 15.38 |
Step 5: Compute Weighted Vote
We assign weight w=1dw = \frac{1}{d}
S.No | Result | Distance | Weight (1/d) |
---|---|---|---|
5 | Fail | 10.82 | 0.0924 |
6 | Pass | 12.05 | 0.0830 |
4 | Fail | 15.38 | 0.0650 |
Total Weights:
- Fail = 0.0924 + 0.0650 = 0.1574
- Pass = 0.0830
Step 6: Final Prediction
Since Fail has a higher total weight than Pass: