AI Algorithm Exercise & Solution
AI Algorithm Exercise & Solution
Problem: Given the following data points, fit a linear regression model to
predict y from x:
x y
1 2
2 3
3 5
4 7
5 8
Age Class
22 0
25 0
1
Age Class
30 1
35 1
40 1
3. k-NN Problem
Problem: Given the following dataset, classify the point (2, 4) using k-NN with
k=3k = 3k=3:
x y Class
1 2 A
2 3 A
3 3 B
4 4 B
4. k-Means Problem
2
Problem: Perform one iteration of k-means clustering for the following data
points, with k = 2:
x y
1 2
1 4
5 8
7 7
8 8
Solution:
5. DBSCAN Problem
x y
1 1
2 2
8 8
8 9
25 80
Solution:
Points (1, 1) and (2, 2) are within a distance of 2, so they form a cluster.
Points (8, 8) and (8, 9) are also within the distance threshold, forming
another cluster.
Point (25, 80) is isolated and classified as noise.
4
Problems with Solutions
Problem: Given the following data points, find the best-fit line using linear
regression:
x 1 2 3 4 5
y 2 4 5 4 5
5
Problem: Given the following data points, perform logistic regression and
predict the probability of the class label for x=2x = 2x=2.
x 0 1 2 3
y 0 0 1 1
Problem 3: k-NN
Problem: Given the following training set, classify the new point x=6 using k-
NN with k=3:
x 2 4 6 8 10
y 0 0 1 1 1
6
7
8