UNIVERSITY OF SOUTH AFRICA
College of Science, Engineering and Technology
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄
COS4852: Machine Learning
Assignment 3 | 2026, Year Module
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄
COS4852
Module Code:
Machine Learning
Module Name:
Assignment 3 – 2026
Assignment:
Year Module
Module Type:
500 (5 questions × 100 marks)
Total Marks:
Submitted in partial fulfilment of the requirements for Machine Learning, UNISA 2026
,UNISA | COS4852 Machine Learning – Assignment 3
Question 1: K-Nearest Neighbours Classification
1(a) Plotting the instances in the (x, y)-space
The ten labelled instances and the unknown instance V are summarised below.
Table 1: Instances plotted in the (x, y)-space
Instance x y Class
V −5.0 −5.0 Unknown
A1 4.0 4.0 A
A2 4.3 2.5 A
A3 6.5 3.0 A
A4 6.0 4.5 A
B1 7.5 8.5 B
B2 6.5 6.8 B
B3 7.5 6.0 B
B4 5.0 6.5 B
B5 6.7 5.0 B
C1 3.5 2.5 C
10 y
Class A
B1
Class B
8 Class C
B2
B4 V (unknown)
B3
6
B5
A4
A1
4
A3
C1 A2
2
x
−8 −6 −4 −2 2 4 6 8
−2
−4
V
−6
−8
Figure 1: Instances plotted in the (x, y)-space, annotated by class
The important spatial observation is that V lies far to the lower-left of every labelled instance.
Therefore the nearest neighbours are determined entirely by which labelled points lie closest to
(−5, −5).
Page 2 of 23
, UNISA | COS4852 Machine Learning – Assignment 3
1(b) KNN classification of V using the Euclidean distance, k = 5
The Euclidean distance between two points is
p
dE (V, P ) = (xP − xV )2 + (yP − yV )2 .
Since V = (−5, −5), this becomes
p
dE (V, P ) = (xP + 5)2 + (yP + 5)2 .
p √ √
dE (V, A1) = (4 + 5)2 + (4 + 5)2 =
81 + 81 = 162 = 12.728
p √ √
dE (V, A2) = (4.3 + 5)2 + (2.5 + 5)2 = 86.49 + 56.25 = 142.74 = 11.947
p √ √
dE (V, A3) = (6.5 + 5)2 + (3 + 5)2 = 132.25 + 64 = 196.25 = 14.009
p √ √
dE (V, A4) = (6 + 5)2 + (4.5 + 5)2 = 121 + 90.25 = 211.25 = 14.534
p √ √
dE (V, B1) = (7.5 + 5)2 + (8.5 + 5)2 = 156.25 + 182.25 = 338.5 = 18.398
p √ √
dE (V, B2) = (6.5 + 5)2 + (6.8 + 5)2 = 132.25 + 139.24 = 271.49 = 16.477
p √ √
dE (V, B3) = (7.5 + 5)2 + (6 + 5)2 = 156.25 + 121 = 277.25 = 16.651
p √ √
dE (V, B4) = (5 + 5)2 + (6.5 + 5)2 = 100 + 132.25 = 232.25 = 15.240
p √ √
dE (V, B5) = (6.7 + 5)2 + (5 + 5)2 = 136.89 + 100 = 236.89 = 15.391
p √ √
dE (V, C1) = (3.5 + 5)2 + (2.5 + 5)2 = 72.25 + 56.25 = 128.5 = 11.336
Table 2: Euclidean distances from V , ascending order
Rank Instance (Class) Distance
1 C1 (C) 11.336
2 A2 (A) 11.947
3 A1 (A) 12.728
4 A3 (A) 14.009
5 A4 (A) 14.534
6 B4 (B) 15.240
7 B5 (B) 15.391
8 B2 (B) 16.477
9 B3 (B) 16.651
10 B1 (B) 18.398
For k = 5 the five nearest neighbours are C1, A2, A1, A3, A4, with classes C, A, A, A, A.
Counting the votes gives A = 4, B = 0, C = 1. Class A has the majority, so
V = Class A
Page 3 of 23
College of Science, Engineering and Technology
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄
COS4852: Machine Learning
Assignment 3 | 2026, Year Module
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄⋄
COS4852
Module Code:
Machine Learning
Module Name:
Assignment 3 – 2026
Assignment:
Year Module
Module Type:
500 (5 questions × 100 marks)
Total Marks:
Submitted in partial fulfilment of the requirements for Machine Learning, UNISA 2026
,UNISA | COS4852 Machine Learning – Assignment 3
Question 1: K-Nearest Neighbours Classification
1(a) Plotting the instances in the (x, y)-space
The ten labelled instances and the unknown instance V are summarised below.
Table 1: Instances plotted in the (x, y)-space
Instance x y Class
V −5.0 −5.0 Unknown
A1 4.0 4.0 A
A2 4.3 2.5 A
A3 6.5 3.0 A
A4 6.0 4.5 A
B1 7.5 8.5 B
B2 6.5 6.8 B
B3 7.5 6.0 B
B4 5.0 6.5 B
B5 6.7 5.0 B
C1 3.5 2.5 C
10 y
Class A
B1
Class B
8 Class C
B2
B4 V (unknown)
B3
6
B5
A4
A1
4
A3
C1 A2
2
x
−8 −6 −4 −2 2 4 6 8
−2
−4
V
−6
−8
Figure 1: Instances plotted in the (x, y)-space, annotated by class
The important spatial observation is that V lies far to the lower-left of every labelled instance.
Therefore the nearest neighbours are determined entirely by which labelled points lie closest to
(−5, −5).
Page 2 of 23
, UNISA | COS4852 Machine Learning – Assignment 3
1(b) KNN classification of V using the Euclidean distance, k = 5
The Euclidean distance between two points is
p
dE (V, P ) = (xP − xV )2 + (yP − yV )2 .
Since V = (−5, −5), this becomes
p
dE (V, P ) = (xP + 5)2 + (yP + 5)2 .
p √ √
dE (V, A1) = (4 + 5)2 + (4 + 5)2 =
81 + 81 = 162 = 12.728
p √ √
dE (V, A2) = (4.3 + 5)2 + (2.5 + 5)2 = 86.49 + 56.25 = 142.74 = 11.947
p √ √
dE (V, A3) = (6.5 + 5)2 + (3 + 5)2 = 132.25 + 64 = 196.25 = 14.009
p √ √
dE (V, A4) = (6 + 5)2 + (4.5 + 5)2 = 121 + 90.25 = 211.25 = 14.534
p √ √
dE (V, B1) = (7.5 + 5)2 + (8.5 + 5)2 = 156.25 + 182.25 = 338.5 = 18.398
p √ √
dE (V, B2) = (6.5 + 5)2 + (6.8 + 5)2 = 132.25 + 139.24 = 271.49 = 16.477
p √ √
dE (V, B3) = (7.5 + 5)2 + (6 + 5)2 = 156.25 + 121 = 277.25 = 16.651
p √ √
dE (V, B4) = (5 + 5)2 + (6.5 + 5)2 = 100 + 132.25 = 232.25 = 15.240
p √ √
dE (V, B5) = (6.7 + 5)2 + (5 + 5)2 = 136.89 + 100 = 236.89 = 15.391
p √ √
dE (V, C1) = (3.5 + 5)2 + (2.5 + 5)2 = 72.25 + 56.25 = 128.5 = 11.336
Table 2: Euclidean distances from V , ascending order
Rank Instance (Class) Distance
1 C1 (C) 11.336
2 A2 (A) 11.947
3 A1 (A) 12.728
4 A3 (A) 14.009
5 A4 (A) 14.534
6 B4 (B) 15.240
7 B5 (B) 15.391
8 B2 (B) 16.477
9 B3 (B) 16.651
10 B1 (B) 18.398
For k = 5 the five nearest neighbours are C1, A2, A1, A3, A4, with classes C, A, A, A, A.
Counting the votes gives A = 4, B = 0, C = 1. Class A has the majority, so
V = Class A
Page 3 of 23