0% found this document useful (0 votes)
6 views

AI Algorithm Exercise & Solution

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

AI Algorithm Exercise & Solution

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Problems with Solutions

1. Linear Regression Problem

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

Use the least squares method to solve for the coefficients.

2. Logistic Regression Problem

Problem: Given the following dataset, build a logistic regression model to


predict Class (0 or 1) from Age:

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:

1. Randomly initialize centroids (e.g., (1, 2) and (5, 8)).


2. Assign each point to the nearest centroid:
o Points (1, 2), (1, 4) are closer to (1, 2).
o Points (5, 8), (7, 7), (8, 8) are closer to (5, 8).
3. Recompute the centroids:
o New centroid for group 1: Average of (1, 2) and (1, 4) = (1, 3).
o New centroid for group 2: Average of (5, 8), (7, 7), and (8, 8) =
(6.67, 7.67).

5. DBSCAN Problem

Problem: Use DBSCAN to cluster the following points with a distance


threshold of 2 and a minimum of 2 points per cluster:

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.

Thus, the two clusters are:

 Cluster 1: (1, 1), (2, 2)


3
 Cluster 2: (8, 8), (8, 9)

4
Problems with Solutions

Problem 1: Linear Regression

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

Problem 2: Logistic Regression

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

You might also like