



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!




Data Mining Spring 2006 Assignment #1 solution
Problem 1:
Here the data has two dimensions. It makes more sense to give arbitrarily high weightage to the gender attribute as compared to the height attribute. Hence, for any new unseen instances, we will only consider neighbors from amongst previously seen instances of the same gender. We will use simple majority based scheme. In case of ties, we will break it towards the extra neighbor since the class has implicit order – small, medium and tall.
a) John [M, 2.0 m] The five nearest neighbors are Jim [Tall], Steven [Tall], Todd [Medium], Worth [Tall] and Bob [Medium]. So the classification will be Tall.
b) Kelly [F, 1.5 m] The four nearest neighbors are Kristina [Short], Kathy [Short], Stephanie [Short], and Lynette [Short]. The fifth neighbor could be one of Martha [Medium], Debbie [Medium], and Amy [Medium]. So the classification will be Short.
c) Sam [M, 2.4 m] The five nearest neighbors are Worth [Tall], Steven [Tall], Jim [Tall], Todd [Medium] and Bob [Medium]. So the classification will be Tall.
d) Laura [F, 1.8 m] The three nearest neighbors are Martha [Medium], Debbie [Medium], and Amy [Medium]. For the remaining two neighbors we can pick any two amongst Maggie [Medium], Stephanie [Short], Kim [Medium], and Lynette [Short]. So the classification will be Medium.
e) Mike [M, 1.7 m] The five nearest neighbors are Dave [Short], Bob [Medium], Todd [Medium], Jim [Tall], and Steven [Tall]. Here, we have a tie between Medium and Tall. The fifth neighbor has class Short, and so we will break the tie towards that. So the classification will be Medium.
Data Mining Spring 2006 Assignment #1 solution
a) For the classification function, the number of + classifications are 4 and the number of – classifications are 5. Hence, the entropy of this collection with respect to the + class: Entropy = – (4/9) log 2 (4/9) = 0. = 0.
b)
Now if we split on a 1 and a 2 then,
a 1 N 1 N 2 a2 N 1 N 2
Entropy(N 1 ) = 0.81 Entropy(N 1 ) = 1. Entropy(N 2 ) = 0.72 Entropy(N 2 ) = 0.
∆gain = 0.99 – (4/9)(0.81) – (5/9)(0.72) ∆gain = 0.99 – (4/9)(1.00) – (5/9)(0.97) = 0.23 = 0.
c)
a3 1.0 3.0 4.0 5.0 6.0 7.0 8. Split 0.5 2.0 3.5 4.5 5.5 6.5 7.5 8. + 0 4 1 3 1 3 2 2 2 2 3 1 4 0 4 0
- 0 5 0 5 1 4 1 4 3 2 3 2 4 1 5 0 Entropy^0 0.99^ 0 0.95 1.00^ 0.99^ 0.92^ 0.92^ 0.97^ 1.00^ 1.00^ 0.92^ 1.00^0 0.99^0 ∆gain 0.00 0.15 0.00 0.07 0.01 0.02 0.10 0.
Hence, the best split for a 3 is 2.0.
d) Based on the calculations we made in part (b) and (c), the best split is a 1.
Data Mining Spring 2006 Assignment #1 solution
a) Optimistic Generalization Error rate = Re-substitution error rate = Number of misclassification / Number of instances = 5 / 10 = 50%
b) Pessimistic Generalization Error rate Number of leaf nodes = 4 Number of misclassifications = 5 out of 10
Therefore, pessimistic generalization error rate = (5 + 0.5*4) / 10 = 70%
c) Using the validation set, number of misclassifications = 1 out of 5 Therefore, the generalization error rate = 1 / 5 = 20%
Data Mining Spring 2006 Assignment #1 solution
Tree (a)
Number of non-leaf nodes = 2 Number of leaf nodes = 3 Number of errors = 7 Number of classes = 3 Number of attributes = 16 Number of records = n
Hence, Cost(tree) = 2 log 2 16 + 3 log 2 3 = 24 + 31.585 = 8 + 4.755 = 12.755 bits Cost(data | tree) = 7 log 2 n = 7 log 2 n bits Cost(tree, data) = 12.755 + 7 log 2 n bits
Tree (b)
Number of non-leaf nodes = 4 Number of leaf nodes = 5 Number of errors = 4 Number of classes = 3 Number of attributes = 16 Number of records = n
Hence, Cost(tree) = 4 log 2 16 + 5 log 2 3 = 44 + 51.585 = 16 + 7.925 = 23.925 bits Cost(data | tree) = 4 log 2 n = 4 log 2 n bits Cost(tree, data) = 23.925 + 4 log 2 n bits
Solving for n in 23.925 + 4 log 2 n = 12.755 + 7 log 2 n , we get, n = 13.208. Hence, according to MDL principle, decision tree (b) is better if n ≥ 14 and tree (a) is better otherwise.
Data Mining Spring 2006 Assignment #1 solution
a) P(A=1 | +) = 3/5 P(A=1 | −) = 2/5 P(B=1 | +) = 1/5 P(B=1 | −) = 2/ P(C=1 | +) = 4/5 P(C=1 | −) = 5/5 P(A=0 | +) = 2/5 P(A=0 | −) = 3/ P(B=0 | +) = 4/5 P(B=0 | −) = 3/5 P(C=0 | +) = 1/5 P(C=0 | −) = 0/
b) P(+) = 5/10 P(−) = 5/
P(+ | A=0, B=1, C=0) = {P(A=0 | +) * P(B=1 | +) * P(C=0 | +) * P(+)} / {P(A=0) * P(B=1) * P(C=0)} = {2/5 * 1/5 * 1/5 * 5/10} / q where q = P(A=0) * P(B=1) * P(C=0) = 0.008 / q P(− | A=0, B=1, C=0) = {P(A=0 | −) * P(B=1 | −) * P(C=0 | −) * P(−)} / {P(A=0) * P(B=1) * P(C=0)} = {3/5 * 2/5 * 0/5 * 5/10} / q = 0 / q
Hence, classification = +.
c) Using p = ½ and m = 4 in the formula 5.18, you can calculate P(A=1 | +) = 5/9 P(A=1 | −) = 4/9 P(B=1 | +) = 3/9 P(B=1 | −) = 4/ P(C=1 | +) = 6/9 P(C=1 | −) = 7/9 P(A=0 | +) = 4/9 P(A=0 | −) = 5/ P(B=0 | +) = 6/9 P(B=0 | −) = 5/9 P(C=0 | +) = 3/9 P(C=0 | −) = 2/
d) Using the values calculated in (c) P(+ | A=0, B=1, C=0) = {P(A=0 | +) * P(B=1 | +) * P(C=0 | +) * P(+)} / {P(A=0) * P(B=1) * P(C=0)} = {4/9 * 3/9 * 3/9 * 5/10} / q = 0.0247 / q P(− | A=0, B=1, C=0) = {P(A=0 | −) * P(B=1 | −) * P(C=0 | −) * P(−)} / {P(A=0) * P(B=1) * P(C=0)} = {5/9 * 4/9 * 2/9 * 5/10} / {5/10 * 3/10 * 1/10} = 0.0274 / q
Hence, classification = −.