Professional Documents
Culture Documents
SML_Assignment_Homework_1
SML_Assignment_Homework_1
SML_Assignment_Homework_1
Problem 1
T
Solution: As X and Y are disjoint events (P (X Y ) = 0) and P(Y) is greater than 0, so
T
P (X Y )
b) P (X|Y ) = =0
P (Y )
Solution:
Number of times head occurs
P (Head) =
Total number of tosses
15
= = 0.75
20
d)
1
CSE 575 Homework #1 Problem 2
Problem 2
Solution: (a) The least-square error function for a linear classifier can be calculated as,
N
1X T
E(w) = (w xn − tn )2
2 n=1
(b) Taking the derivative of this error function and equating it to 0, we get,
1 1 0 1
1 2 1 1
x=
1
, t=
2 3 0
1 3 3 0
a) So after solving this above equation using numpy we get w0 = 0.9445, w1 = 0.1667 and w2 = −0.4445
Solution: a) The error function for the Fisher’s linear discriminant can be given as
(m2 − m1 )2
J(W ) =
s21 + s22
W T SB W
J(W ) = (in marix format)
W T SW W
b) Sw = S1 + S2 and,
Ci
X
Si = (xn − mi ) ∗ (xn − mi )T
n=1
As the first two are classified as 1 and others are classified as 0,
1
m1 = (x1 + x2 )
2
1
m2 = (x3 + x4 )
2
Calcuating Sw inverse,
Problem 3
Solution: Given p(y = 1) = 0.4, the prior for the class label y = 2 is,
a) p(y = 2) = 1 − p(y = 1) = 1 − 0.4 = 0.6
Solution: Given p(x|y = 1) = 0.5 f or 0 ≤ x ≤ 2 and 0 otherwise and p(x|y = 2) = 0.125 f or 0 ≤ x ≤ 8 and
0 otherwise. Using the Bayes theorem,
p(x|y = 1) ∗ p(y = 1)
p(y = 1|x) = P2
n=1 p(x|y = n) ∗ p(y = n)
p(x|y = 1) ∗ p(y = 1)
=
p(x|y = 1) ∗ p(y = 1) + p(x|y = 2) ∗ p(y = 2)
0.5 ∗ 0.4
=
0.5 ∗ 0.4 + 0.125 ∗ 0.6
0.2
=
0.275
= 0.727
b)
Solution: Given p(x|y = 1) = 0.5 f or 0 ≤ x ≤ 2 and 0 otherwise and p(x|y = 2) = 0.125 f or 0 ≤ x ≤ 8 and
0 otherwise. Let’s calculate p(y = 1|x = 1) and p(y = 2|x = 1) so,
p(x|y = 1) ∗ p(y = 1)
p(y = 1|x) =
p(x|y = 1) ∗ p(y = 1) + p(x|y = 2) ∗ p(y = 2)
= 0.727 (as calculated in (b))
p(x|y = 2) ∗ p(y = 2)
p(y = 2|x) =
p(x|y = 2) ∗ p(y = 1) + p(x|y = 2) ∗ p(y = 2)
0.125 ∗ 0.6
=
0.275
= 0.273
Solution: From (c), we can define the decision function of the Bayes Classifier as:
y = 1 for 0 ≤ x ≤ 2 (as p(y = 1|x) > p(y = 2|x) for this interval),
y = 2 for 2 < x ≤ 8 (as p(y = 1|x) < p(y = 2|x) for this interval),
d) and for values of x ̸∈ [0, 8], y can be 1 or 2.
Problem 4
Solution: Given p(y = 1) = 0.6, the prior for the class label y = 2 is,
a) p(y = 2) = 1 − p(y = 1) = 1 − 0.6 = 0.4
Solution: For calculating p(y = 1|x), we have to calculate it for all pairs of (x1 , x2 ) which are (0,0), (0,1),
(1,0) and (1,1) so,
Solution: Using the probabilities from (b) and (c), the decision function of the Bayes classifier will be,
Problem 5
Solution: The number of independent in the Naive Bayes Classifier are 10 (2 for Sky, 3 for Temp, 2 for
a) Humid and 2 for Wind and 1 class label as Play Sport)
3
Solution: p(x1 = sunny|y = yes) =
4
3
p(x1 = sunny|y = no) =
6
1
p(x1 = rainy|y = yes) =
4
3
p(x1 = rainy|y = no) =
6
2
p(x2 = mild|y = yes) =
4
2
p(x2 = mild|y = no) =
6
1
p(x2 = cold|y = yes) =
4
2
p(x2 = cold|y = no) =
6
1
p(x2 = hot|y = yes) =
4
2
p(x2 = hot|y = no) =
6
4
p(x3 = normal|y = yes) =
4
2
p(x3 = normal|y = no) =
6
0
p(x3 = high|y = yes) =
4
4
p(x3 = high|y = no) =
6
2
p(x4 = strong|y = yes) =
4
4
p(x4 = strong|y = no) =
6
2
p(x4 = mild|y = yes) =
4
2
b) p(x4 = mild|y = no) =
6
Solution: New input vector x = (sunny, cold, normal, strong), so p(y = 1|x) can be calculated by calculating
the class conditional probabilities for x1 = sunny, x2 = cold, x3 = normal and x4 = strong.
Solution: We can ignore the parameters which are missing as these are independent events. Hence,
d) Hence as p(y = 1|x) > p(y = 2|x), so the classifier align the label as y = 0 (No).