๐Ÿง  Machine Learning Tasks

Complete Solutions with Detailed Calculations

1

Classifier Evaluation

Given Confusion Matrix:

Predicted P Predicted N
Actual P TP = 20 FN = 25
Actual N FP = 35 TN = 40

Calculations:

2

k-NN Classifier (k=3)

Class A: a=(0,2,1), b=(3,1,0), c=(0,1,-1)
Class B: d=(3,-1,2), e=(0,2,3), f=(-1,2,3)
Classify: x = (2,-1,3)

Euclidean Distances:

Vector Class Distance
aAโˆš17 โ‰ˆ 4.123
bAโˆš14 โ‰ˆ 3.742
cAโˆš24 โ‰ˆ 4.899
dBโˆš2 โ‰ˆ 1.414 โญ
eBโˆš13 โ‰ˆ 3.606 โญ
fBโˆš18 โ‰ˆ 4.243

3 Nearest Neighbors:

x belongs to Class B (2 votes for B, 1 vote for A)
3

Naive Bayes Classifier

Training set: rows 2-13 of outdoor game table
Case to classify: row 1 (Sunny, Hot, High, Weak)

Prior Probabilities:

Conditional Probabilities:

Attribute P(attr|No) P(attr|Yes)
Sunny3/52/7
Hot2/52/7
High4/53/7
Weak2/54/7

Posterior Calculations:

P(No|X) โˆ (5/12) ร— (3/5) ร— (2/5) ร— (4/5) ร— (2/5) = 0.0384
P(Yes|X) โˆ (7/12) ร— (2/7) ร— (2/7) ร— (3/7) ร— (4/7) = 0.0116
Classification: No (don't play)
4

Perceptron

Input: p = (0, 2, -1, -2)
Weights: w = (1, -1, 1, 2)
Threshold: t = -1 | Learning rate: ฮฑ = 1

a) Compute Output:

net = p ยท w = (0ร—1) + (2ร—-1) + (-1ร—1) + (-2ร—2) = 0 - 2 - 1 - 4 = -7

Since net = -7 < t = -1: Output y = 0

b) Modified Weight Vector:

w_new = w + ฮฑ ร— error ร— p
= (1, -1, 1, 2) + 1 ร— 1 ร— (0, 2, -1, -2)
= (1, 1, 0, 0)

c) Threshold Adjustment:

t_new = t - ฮฑ ร— error = -1 - 1 ร— 1 = -2
Threshold is decreased (from -1 to -2)
5

k-Means Algorithm

Vectors: a=(0,1,1,0), b=(3,3,-1,3), c=(-1,2,0,0), d=(2,2,0,1)
Initial centroids: cโ‚=(1,1,0,0), cโ‚‚=(2,3,0,3)

Iteration 1 - Assignments:

Vector d(ยท, cโ‚) d(ยท, cโ‚‚) Assignment
aโˆš2 โ‰ˆ 1.41โˆš18 โ‰ˆ 4.24Cluster 1
bโˆš18 โ‰ˆ 4.24โˆš2 โ‰ˆ 1.41Cluster 2
cโˆš5 โ‰ˆ 2.24โˆš19 โ‰ˆ 4.36Cluster 1
dโˆš3 โ‰ˆ 1.73โˆš5 โ‰ˆ 2.24Cluster 1

Updated Centroids:

Iteration 2: No changes โ†’ Algorithm converges!

Final Cluster 1: {a, c, d}
Final Cluster 2: {b}
Final cโ‚: (0.33, 1.67, 0.33, 0.33)
Final cโ‚‚: (3, 3, -1, 3)
6

Vector Operations

v = (2, -1, 2, 2)
w = (1, -2, 3, 1)

a) Orthogonality Test:

v ยท w = (2ร—1) + (-1ร—-2) + (2ร—3) + (2ร—1) = 2 + 2 + 6 + 2 = 12 โ‰  0
No, vectors are NOT orthogonal

b) Length Comparison:

||v|| = โˆš(4 + 1 + 4 + 4) = โˆš13 โ‰ˆ 3.61
||w|| = โˆš(1 + 4 + 9 + 1) = โˆš15 โ‰ˆ 3.87
No, v is NOT longer than w (โˆš13 < โˆš15)

c) Distance:

d(v, w) = โˆš[(2-1)ยฒ + (-1-(-2))ยฒ + (2-3)ยฒ + (2-1)ยฒ] = โˆš[1+1+1+1] = โˆš4 = 2
Distance = 2
7

Knapsack Problem

Capacity: C = 5
Items: {a, b, c, d, e}
Values: v = (3, 1, 2, 2, 2)
Weights: w = (4, 1, 2, 3, 1)

Item Analysis:

Item Value Weight Value/Weight
a340.75
b111.00
c221.00
d230.67
e212.00 โญ

Optimal Combinations:

Combination Weight Value
{b, c, e}45
{b, d, e}55
{a, e}55
{c, d}54
{a, b}54
Optimal Solution Value = 5 (achievable with {b,c,e}, {b,d,e}, or {a,e})