UNIVERSITY OF SOUTH AFRICA (UNISA)
College of Science, Engineering and Technology
⋄
Machine Learning Assignment
Semester 2 – 2026
⋄
Module Code: COS4852
Module Name: Machine Learning
Assignment No.: 03
Semester: Semester 2, 2026
Submitted in partial fulfilment of the requirements for Machine Learning
at the University of South Africa.
, Question 1
Consider the following dataset consisting of 10 instances in (x,y) coordinates, classified as Class A,
B, or C:
A1 : (4.0,4.0) - Class A
A2 : (4.3,2.5) - Class A
A3 : (6.5,3.0) - Class A
A4 : (6.0,4.5) - Class A
B1 : (7.5,8.5) - Class B
B2 : (6.5,6.8) - Class B
B3 : (7.5,6.0) - Class B
B4 : (5.0,6.5) - Class B
B5 : (6.7,5.0) - Class B C1 :
(3.5,2.5) - Class C
A new instance V of unknown class is at (-5.0, -5.0).
a) Draw an accurate diagram to show all the instances in the (x,y)-space. Clearly annotate your
diagram.
b) Use the KNN-algorithm to determine the class of V . First use the Euclidian distance measure
with k = 5. Show all your steps, distance calculations, the order of instances and the process
of selecting the class for the unknown instance V .
c) Repeat the process of finding the class of V using the Manhattan distance measure. Show all
your steps, distance calculations, ordering of instances, and the process of selecting the class.
BONUS Use your diagram to show the full extent of the areas covered by each distance measure that
includes the 5 nearest neighbours from the new intances V . Think carefully how Euclidian and
Manhattan distances are defined in 2D space.
[100]
,UNISA | COS4852 Machine Learning: KNN Classification
Question 1: K-Nearest Neighbour Classification
The dataset consists of ten labelled instances belonging to Class A, Class B, or Class C, to-
gether with one unlabelled instance V at (−5.0, −5.0) whose class must be determined using
the K-Nearest Neighbour (KNN) algorithm.
1(a) Diagram of the Instances in (x, y)-Space
The coordinates of all instances, including the unknown instance V , are summarised below
before being plotted.
Table 1: Coordinates and class labels of all instances
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
The scatter plot below places every instance on the same set of axes. V lies far to the lower-
left of all ten labelled points, so its nearest neighbours are simply whichever labelled points
sit closest to the bottom-left corner of the plotted space.
1(b) KNN Classification of V Using Euclidean Distance (k = 5)
The Euclidean distance between V = (−5, −5) and any point P = (xP , yP ) is
p
dE (V, P ) = (xP + 5)2 + (yP + 5)2 .
Applying this formula to each of the ten instances gives the following distances. The calcula-
tion for A1 is shown in full as an example, and the same procedure is used for the remaining
nine points.
Page 1 of 7
, UNISA | COS4852 Machine Learning: KNN Classification
y B1 Class A
8 Class B
B2 Class C
B4
B3 V (unknown)
6
A4
B5
A1
4
A3
C1 A2
2
x
−6 −4 −2 2 4 6 8
−2
−4
V
−6
Figure 1: All ten labelled instances and the unknown instance V plotted in (x, y)-space
p √ √
dE (V, A1) = (4 + 5)2 + (4 + 5)2 = 81 + 81 = 162 = 12.728.
p √ √
dE (V, A2) = 9.32 + 7.52 = 86.49 + 56.25 = 142.74 = 11.947.
p √ √
dE (V, A3) = 11.52 + 82 = 132.25 + 64 = 196.25 = 14.009.
p √ √
dE (V, A4) = 112 + 9.52 = 121 + 90.25 = 211.25 = 14.534.
p √ √
dE (V, B1) = 12.52 + 13.52 = 156.25 + 182.25 = 338.5 = 18.398.
p √ √
dE (V, B2) = 11.52 + 11.82 = 132.25 + 139.24 = 271.49 = 16.477.
p √ √
dE (V, B3) = 12.52 + 112 = 156.25 + 121 = 277.25 = 16.651.
Page 2 of 7
College of Science, Engineering and Technology
⋄
Machine Learning Assignment
Semester 2 – 2026
⋄
Module Code: COS4852
Module Name: Machine Learning
Assignment No.: 03
Semester: Semester 2, 2026
Submitted in partial fulfilment of the requirements for Machine Learning
at the University of South Africa.
, Question 1
Consider the following dataset consisting of 10 instances in (x,y) coordinates, classified as Class A,
B, or C:
A1 : (4.0,4.0) - Class A
A2 : (4.3,2.5) - Class A
A3 : (6.5,3.0) - Class A
A4 : (6.0,4.5) - Class A
B1 : (7.5,8.5) - Class B
B2 : (6.5,6.8) - Class B
B3 : (7.5,6.0) - Class B
B4 : (5.0,6.5) - Class B
B5 : (6.7,5.0) - Class B C1 :
(3.5,2.5) - Class C
A new instance V of unknown class is at (-5.0, -5.0).
a) Draw an accurate diagram to show all the instances in the (x,y)-space. Clearly annotate your
diagram.
b) Use the KNN-algorithm to determine the class of V . First use the Euclidian distance measure
with k = 5. Show all your steps, distance calculations, the order of instances and the process
of selecting the class for the unknown instance V .
c) Repeat the process of finding the class of V using the Manhattan distance measure. Show all
your steps, distance calculations, ordering of instances, and the process of selecting the class.
BONUS Use your diagram to show the full extent of the areas covered by each distance measure that
includes the 5 nearest neighbours from the new intances V . Think carefully how Euclidian and
Manhattan distances are defined in 2D space.
[100]
,UNISA | COS4852 Machine Learning: KNN Classification
Question 1: K-Nearest Neighbour Classification
The dataset consists of ten labelled instances belonging to Class A, Class B, or Class C, to-
gether with one unlabelled instance V at (−5.0, −5.0) whose class must be determined using
the K-Nearest Neighbour (KNN) algorithm.
1(a) Diagram of the Instances in (x, y)-Space
The coordinates of all instances, including the unknown instance V , are summarised below
before being plotted.
Table 1: Coordinates and class labels of all instances
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
The scatter plot below places every instance on the same set of axes. V lies far to the lower-
left of all ten labelled points, so its nearest neighbours are simply whichever labelled points
sit closest to the bottom-left corner of the plotted space.
1(b) KNN Classification of V Using Euclidean Distance (k = 5)
The Euclidean distance between V = (−5, −5) and any point P = (xP , yP ) is
p
dE (V, P ) = (xP + 5)2 + (yP + 5)2 .
Applying this formula to each of the ten instances gives the following distances. The calcula-
tion for A1 is shown in full as an example, and the same procedure is used for the remaining
nine points.
Page 1 of 7
, UNISA | COS4852 Machine Learning: KNN Classification
y B1 Class A
8 Class B
B2 Class C
B4
B3 V (unknown)
6
A4
B5
A1
4
A3
C1 A2
2
x
−6 −4 −2 2 4 6 8
−2
−4
V
−6
Figure 1: All ten labelled instances and the unknown instance V plotted in (x, y)-space
p √ √
dE (V, A1) = (4 + 5)2 + (4 + 5)2 = 81 + 81 = 162 = 12.728.
p √ √
dE (V, A2) = 9.32 + 7.52 = 86.49 + 56.25 = 142.74 = 11.947.
p √ √
dE (V, A3) = 11.52 + 82 = 132.25 + 64 = 196.25 = 14.009.
p √ √
dE (V, A4) = 112 + 9.52 = 121 + 90.25 = 211.25 = 14.534.
p √ √
dE (V, B1) = 12.52 + 13.52 = 156.25 + 182.25 = 338.5 = 18.398.
p √ √
dE (V, B2) = 11.52 + 11.82 = 132.25 + 139.24 = 271.49 = 16.477.
p √ √
dE (V, B3) = 12.52 + 112 = 156.25 + 121 = 277.25 = 16.651.
Page 2 of 7