Given Confusion Matrix:
|
Predicted P |
Predicted N |
| Actual P |
TP = 20 |
FN = 25 |
| Actual N |
FP = 35 |
TN = 40 |
Calculations:
- Accuracy = (TP + TN) / Total = (20 + 40) / 120 = 0.5 (50%)
- Precision = TP / (TP + FP) = 20 / 55 = 0.364 (36.4%)
- Recall = TP / (TP + FN) = 20 / 45 = 0.444 (44.4%)
- F-measure = 2 ร (P ร R) / (P + R) = 0.4 (40%)
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 |
| a | A | โ17 โ 4.123 |
| b | A | โ14 โ 3.742 |
| c | A | โ24 โ 4.899 |
| d | B | โ2 โ 1.414 โญ |
| e | B | โ13 โ 3.606 โญ |
| f | B | โ18 โ 4.243 |
3 Nearest Neighbors:
- d (โ2) โ Class B
- e (โ13) โ Class B
- b (โ14) โ Class A
x belongs to Class B (2 votes for B, 1 vote for A)
Training set: rows 2-13 of outdoor game table
Case to classify: row 1 (Sunny, Hot, High, Weak)
Prior Probabilities:
- P(Yes) = 7/12
- P(No) = 5/12
Conditional Probabilities:
| Attribute |
P(attr|No) |
P(attr|Yes) |
| Sunny | 3/5 | 2/7 |
| Hot | 2/5 | 2/7 |
| High | 4/5 | 3/7 |
| Weak | 2/5 | 4/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)
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)
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.24 | Cluster 1 |
| b | โ18 โ 4.24 | โ2 โ 1.41 | Cluster 2 |
| c | โ5 โ 2.24 | โ19 โ 4.36 | Cluster 1 |
| d | โ3 โ 1.73 | โ5 โ 2.24 | Cluster 1 |
Updated Centroids:
- cโ = ((0-1+2)/3, (1+2+2)/3, (1+0+0)/3, (0+0+1)/3) = (1/3, 5/3, 1/3, 1/3)
- cโ = (3, 3, -1, 3)
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)
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
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 |
| a | 3 | 4 | 0.75 |
| b | 1 | 1 | 1.00 |
| c | 2 | 2 | 1.00 |
| d | 2 | 3 | 0.67 |
| e | 2 | 1 | 2.00 โญ |
Optimal Combinations:
| Combination |
Weight |
Value |
| {b, c, e} | 4 | 5 |
| {b, d, e} | 5 | 5 |
| {a, e} | 5 | 5 |
| {c, d} | 5 | 4 |
| {a, b} | 5 | 4 |
Optimal Solution Value = 5 (achievable with {b,c,e}, {b,d,e}, or {a,e})