Apply Weighted KNN Algorithm using the given dataset to classify the test set data (7.6, 60, 8) where k = 3

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.NoCGPAAssessmentProjectResult
19.2858Pass
28.0807Pass
38.5818Pass
46.0455Fail
56.5504Fail
68.2727Pass
75.8385Fail
88.9919Pass

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.NoCGPAAssessProjectResultDistance
19.2858Pass√((7.6−9.2)² + (60−85)² + (8−8)²) = √((−1.6)² + (−25)²) = √(2.56 + 625) = √627.56 ≈ 25.05
28.0807Pass√((−0.4)² + (−20)² + 1²) = √(0.16 + 400 + 1) = √401.16 ≈ 20.02
38.5818Pass√((−0.9)² + (−21)²) = √(0.81 + 441) = √441.81 ≈ 21.02
46.0455Fail√((1.6)² + (15)² + 3²) = √(2.56 + 225 + 9) = √236.56 ≈ 15.38
56.5504Fail√((1.1)² + 10² + 4²) = √(1.21 + 100 + 16) = √117.21 ≈ 10.82
68.2727Pass√((−0.6)² + (−12)² + 1²) = √(0.36 + 144 + 1) = √145.36 ≈ 12.05
75.8385Fail√((1.8)² + 22² + 3²) = √(3.24 + 484 + 9) = √496.24 ≈ 22.28
88.9919Pass√((−1.3)² + (−31)² + (−1)²) = √(1.69 + 961 + 1) = √963.69 ≈ 31.03

Step 4: Select K = 3 Nearest Neighbors

Sort by distance:

S.NoResultDistance
5Fail10.82
6Pass12.05
4Fail15.38

Step 5: Compute Weighted Vote

We assign weight w=1dw = \frac{1}{d}

S.NoResultDistanceWeight (1/d)
5Fail10.820.0924
6Pass12.050.0830
4Fail15.380.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:

Predicted Result = Fail

Leave a Reply

Your email address will not be published. Required fields are marked *