




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Question1: a)
P (a, b, c, d) = P (a)P (b)P (c|a, b)P (d|b, c) = 0. 2 ∗ 0. 7 ∗ 0. 9 ∗ 0. 1 = 0. 0126
b)
P (b, c, ¬d) = ΣaP (c|a, b)P (a)P (b)P (¬d|b, c) = (0. 9 ∗ 0 , 2 ∗ +0. 5 ∗ 0 .8) ∗ 0. 7 ∗ 0. 9 = 0. 3654
b)
P (c|b, ¬d) = αP (b, c, ¬d) = α ∗ 0 .3654(f romb) P (¬c|b, ¬d) = αP (b, ¬c, ¬d) = αΣaP (¬c|a, b)P (a)P (b)P (¬d|b, ¬c) = α(0. 1 ∗ 0 , 2 ∗ +0. 5 ∗ 0 .8) ∗ 0. 7 ∗ 0. 7 = α ∗ 0. 2058
So, P (C|b, ¬d) ≈< 0. 6397 , 0. 3603 >. Then we get the answer 0.6397.
Question2: The algorithm may not return the same tree, but it will return a tree that is log- ically equivalent, assuming that the method for generating the training set eventu- ally generates all possible combinations of attributes. For example, if the method picks the value of each attribute uniformly at random, the probability that it gen- erates all possible combinations goes to one when the training set goes to infinity. The form of the tree may not be the same, because there are multiple ways of representing the same logical function.
Question3:
This happens when 25 examples are true and the other 25 examples are false. Because the simple majority classifier is used in leave-one-out cross validation, the output is always wrong in this case. For example, we choose one ’true’ ex- ample as the testing data and the other 49 examples as the training data. Because of the simple majority classifier, it predicts ’false’ for all input. Obviously, this is wrong for the testing example.
Question4: a Label the leaf with a value α ∈ [0, 1], where labeling the leaf with 1 corre- sponds to yes or positive, labeling the leaf with 0 corresponds to no or negative, and labeling the leaf with a value 0 < α < 1 is interpreted to be a probability or likelihood. Given that the leaf is labeled with α, where α ∈ [0, 1], the absolute error for one training example is given by | 1 − α|, if the training example is posi- tive, and | 0 − α|, if the training example is negative. The total absolute error over all p + n training examples at that leaf is given by,
E = p| 1 − α| + n| 0 − α| = p(1 − α) + nα = α(n − p) + p
It can be seen that if n ¿ p, the term (n − p) is greater than zero and thus E is minimized if α = 0. And if n < p, the term (n − p) is less than zero and thus E is minimized if α = 1. In other words, the total absolute error is minimized if the leaf is labeled with the majority classification. b Given that the leaf is labeled with α, where α ∈ [0, 1], the squared error for one training example is given by (1 − α)^2 , if the training example is positive, and (0 − α)^2 , if the training example is negative. The total squared error over all p + n training examples at that leaf is given by,
E = p(1 − α)^2 + n(0 − α)^2 = p(1 − α)^2 + nα^2 = (p + n)α^2 − 2 pα + p
Taking the first derivative of E with respect to α gives, 2(p + n)α − 2 p The condition under which the total error E is minimized can be found by setting the first derivative equal to zero and solving for α, α = p/(p + n) (We also need to verify that the second derivative is greater than 0 to be sure that we are minimizing
convex function :
I(tp + (1 − t)q) ≤ tI(p) + (1 − t)I(q) (2)
for two numbers 0 ≤ p, q, ≤ 1 and 0 ≤ t ≤ 1. Note that when p = q, the inequality becomes an equality : I(p) = I(p). Assuming this inequality, we have
Gain(E) = I(
p p + n
n p + n
) − Remainder(E)
p p + n
n p + n
) − Σ^2 i=
pi + ni p + n
pi pi + ni
ni pi + ni
p p + n
) − Σ^2 i=
pi + ni p + n
pi pi + ni
To use Equation 2, take t = p^1 p++nn^1 , p = (^) p 1 p+^1 n 1 , q = (^) p 2 p+^2 n 2. Note that 1 − t = p^2 p++nn^2. Plug everything in Equation 2, we have
I(
p p + n
p 1 + n 1 p + n
p 1 p 1 + n 1
p 2 + n 2 p + n
p 2 p 2 + n 2
That is Gain(E) > 0. What’s left is to establish Equation 2, i.e., to show that I(p) is a convex function. The simplest thing to do is to show that I ′′ (p) < 0. We compute
I
′ (p) = − log p + log(1 − p) I ′′ (p) = − 1 /p − 1 /(1 − p) = − 1 /(p(1 − p)) < 0.
Gain(E) = I(
p p + n
n p + n
) − Remainder(E)
p p + n
n p + n
) − Σvi=
pi + ni p + n
pi pi + ni
ni pi + ni
If the ratio pi/(pi + ni) is the same for all i, we get
Gain(E) = I(
p p + n
n p + n
) − Σvi=
pi + ni p + n
pi pi + ni
ni pi + ni
p p + n
n p + n
pi pi + ni
ni pi + ni
)Σvi=
pi + ni p + n = I(
p p + n
n p + n
pi pi + ni
ni pi + ni
p p + n
n p + n
p p + n
n p + n
Thus, we have shown that Σvi=1^ p pi++nni I( (^) pi+pini , (^) pin+ini ) gets its maximal value when the ratio pi/(pi + ni) is the same for all i.
Question7:
L = Σmj=1log √ 21 πσ e−^
(yj −(θ 1 xj +θ 2 ))^2 2 σ^2 = m(−log
2 π−logσ)−Σmj=1(yj^ −(θ^1 xj^ +θ^2 ))
2 2 σ^2 ∂L θ 1 =^ −^
1 σ^2 Σ
m j=1(yj^ −^ (θ^1 xj^ +^ θ^2 ))xj^ = 0(eqation1)^ ⇒^ θ^2 =^
Σj (yj −θ 1 xj ) m ∂L θ 2 =^ −^
1 σ^2 Σ
m j=1(yj^ −^ (θ^1 xj^ +^ θ^2 )) = 0(eqation2) From eqation 1 and 2, we get θ 1 = Σj (yj xj − xmj Σiyi) Σj (x^2 j − Σmix ixj ) and
∂L σ =^ −^
1 σ +^
1 σ^3 Σ
m j=1(yj^ −^ (θ^1 xj^ +^ θ^2 )) (^2) = 0 ⇒ σ =
Σmj=1(yj −(θ 1 xj +θ 2 ))^2 m
Question8: We went over this problem in class. So allow me to be brief. a) This is actuallt quite easy to understand. If we only have two attributes, say Flavor and Wrapper, then we have to determine the values of five variables, θ, θF 1 , θF 2 , θW 1 , θW 2. Now, look at the table on page 729. Of course, the table on that page is for the case of three attributes. For the two attribute case, we will only have four entries. That is, we can only observe four different “kinds” of candies, and we have to determine five parameters. Therefore, the problem is under-constrained. However, for the three attribute case discussed in the textbook (and in class), we have eight entries in the table and there are only seven parameters to be deter- mined. That is, we have more “observations” than the number of parameters to be determined. That’s why we can expect a solution in this case.
b) Here, we show how to compute θ F(1) 1 and θ F(1) 2. The others are similar. Note that θ^1 has been computed in the textbook (pages 729-730). Similar to θ(1)^ on page 729, we have
θ F(1) 1 =
N (F lavor = cherry, Bag = 1) N (Bag = 1)
where N (F lavor = cherry, Bag = 1) is the number of candies with cherry flavor and from Bag one. The denominator was determined on page 729 to be (^612) ∑. We have to calculate the numerator. N (F lavor = cherry, Bag = 1) =
j
P (Fj =C|B=1)P (Wj |B=1)P (Hj |B=1)P (B=1) P (Fj =C|B=1)P (Wj |B=1)P (Hj |B=1)P (B=1)+P (Fj =C|B=2)P (Wj |B=2)P (Hj |B=2)P (B=2) , and this is, ∑ j
θ F(0) 1 θ W(0) 1 θ H(0) 1 θ(0) θ(0) F 1 θ(0) W 1 θ(0) H 1 θ(0)+θ(0) F 2 θ W(0) 2 θ H^02 (1−θ(0)).
numerator
N (F lavor = cherry, Bag = 1) =
j
P (Bag = 1|Fj = cherry, Wj , Hj )
is just θ(1) F 1 = (273 + 93 + 104 + 90) × θ(0)^ = 560p because θ(0) F 1 = θ(0) F 2 = θ(0) W 1 =
θ W(0) 2 = θ(0) H 1 = θ(0) H 2. This implies that θ F(1) 1 = 560p/ 1000 p = 0. 56 and similarly,
θ F(1) 2 = 560(1 − p)/1000(1 − p) = 0. 56. That is, after first iteration, we have
θ F(1) 1 = θ F(1) 2 , θ(1) H 1 = θ H(1) 2 and θ W(1) 1 = θ(1) W 2. It is easy to see that the process becomes
stationary after this step, i.e., θ F(1) 1 = · · · = θ( F∞ 1 )and for others. d) The log likelihood is
L = log P ({d 1 , · · · , d 1000 }|{θi}) = log
i
P (di|{θi}) =
i
log(P (di|{θi}))
Use the network (Figure 20.10 on page728), we have the log likelihood
= 273 log(θF 1 θW 1 θH 1 θ + θF 2 θW 2 θH 2 (1 − θ))
At the fixed point reached in part (c), we have further simplification of the sum above:
= 273 log(θF 1 θW 1 θH 1 ) + 93 log(θF 1 θW 1 (1 − θH 1 ))
Now we show that the partial derivatives of L with respect to all variables vanish. Clearly, ∂ ∂θL = 0 from the expression above. Next we compute (^) ∂θ∂LF 1. Using the
fact that ∂^ log(θF ∂θ^1 FθW 1 1 θH^1 )= 1/θF 1 and so on, we have
∂L ∂θF 1
= 560/θF 1 − 440 /(1 − θF 1 ) = 0. (4)
since, from part (c), θF 1 = 0. 560. Similarly, it can be shown that all other partial derivatives of L at the fixed point reached in part (c) are 0.
Question10: We have also covered this problem in class. So allow me to be brief. The margin is 2 and the separating line back in the original Euclidean input space is the union of x and y axes.
Figure 1: The red circles are negative samples (having negative XOR values) and the blue-green circles are positive samples. Originally, they are not linearly separable. However, after applying the transformation f , they become linearly separable.