인공지능 과제4
Homework #4 - solution
2009. 2학기. 인공지능
어떤 정당에서는 과거 일부 유권자의 투표 성향 자료를 분석하여 미래의 새로운 유권자들에 대한 투표 성향을 예측하려고 한다. 아래의 자료는 9명의 유권자들이 과거 여당(+) 또는 야당(-)에 투표한 기록이다. 각 유권자에 대하여 각각 성별(sex), 나이(age), 수입(income)에 대한 데이터가 있다. 이 데이터를 기초로 하여 감독 학습(supervised learning)을 수행하여 유권자의 투표 성향을 예측하는 모델을 만들려고 한다.
example no. |
sex |
age |
income |
vote |
1 |
M |
54 |
3500 |
+ |
2 |
F |
20 |
1200 |
- |
3 |
F |
45 |
4200 |
+ |
4 |
M |
38 |
4800 |
- |
5 |
F |
25 |
0 |
+ |
6 |
M |
30 |
3800 |
- |
7 |
M |
48 |
2200 |
+ |
8 |
F |
32 |
2000 |
+ |
9 |
M |
29 |
2300 |
- |
1. Information gain을 사용하여 decision tree 학습을 수행하는 과정을 보이고, 학습 결과에 따라
유권자 A=(M, 35, 2000)의 성향을 + 또는 -로 분류하시오. 각 attribute의 값은 다음과 같이
변환하여 사용하시오.
age: Old(40이상) 또는 Young(40미만),
income: High(2500이상) 또는 Low(2500미만)
T = {+(1, 3, 5, 7, 8), -(2, 4, 6, 9)}
E(T) = -(5/9)*log2(5/9) (4/9)*log2(4/9) = 0.99
1) p = sex,
T1(M) = {+(1, 7), -(4, 6, 9)} E(T1) = -(2/5)*log2(2/5) (3/5)*log2(3/5) = 0.56
T2(F) = {+(3, 5, 8), -(2)} E(T2) = -(3/4)*log2(3/4) (1/4)*log2(1/4) = 0.44
Gain(sex) = E(T) - ((5/9)*E(T1) + (4/9)*E(T2))
= 0.99 - ((5/9)*0.56 + (4/9)*0.44) = 0.091
2) p = age,
T1(Old) = {+(1, 3, 7), -()} E(T1) = -(3/3)*log2(3/3) (0/3)*log2(0/3) = 0
T2(Young) = {+(5, 8), -(2, 4, 6, 9)} E(T2) = -(2/6)*log2(2/6) (4/6)*log2(4/6) = 0.92
Gain(age) = E(T) - ((3/9)*E(T1) + (6/9)*E(T2))
= 0.99 - ((3/9)*0 + (6/9)*0.92) = 0.379
3) p = income,
T1(High) = {+(1, 3), -(4, 6)} E(T1) = -(2/4)*log2(2/4) (2/4)*log2(2/4) = 1
T2(Low) = {+(5, 7, 8), -(2, 9)} E(T2) = -(3/5)*log2(3/5) (2/5)*log2(2/5) = 0.97
Gain(income) = E(T) - ((4/9)*E(T1) + (5/9)*E(T2))
= 0.99 ((4/9)*1 + (5/9)*0.97) = 0.007
∴ SELECT 'age'
T(age == 'Old') = {+(1, 3, 7), -()} leaf with '+'
T(age == 'Young') = {+(5, 8), -(2, 4, 6, 9)}
E(T) = -(2/6)*log2(2/6) (4/6)*log2(4/6) = 0.92
1) p = sex,
T1(M) = {+(), -(4, 6, 9)} E(T1) = -(0/3)*log2(0/3) (3/3)*log2(3/3) = 0
T2(F) = {+(5, 8), -(2)} E(T2) = -(2/3)*log2(2/3) (1/3)*log2(1/3) = 0.92
Gain(sex) = E(T) - ((3/6)*E(T1) + (3/6)*E(T2))
= 0.92 ((3/6)*0 + (3/6)*0.92) = 0.459
2) p = income,
T1(High) = {+(), -(4, 6)} E(T1) = -(0/2)*log2(0/2) (2/2)*log2(2/2) = 0
T2(Low) = {+(5, 8), -(2, 9)} E(T2) = -(2/4)*log2(2/4) (2/4)*log2(2/4) = 1
Gain(age) = E(T) - ((2/6)*E(T1) + (4/6)*E(T2))
= 0.92 ((2/6)*0 + (4/6)*1) = 0.252
∴ SELECT 'sex'
T((age == 'Young') and (sex == 'M')) = {+(), -(4, 6, 9)} leaf with '-'
T((age == 'Young') and (sex == 'F'))의 경우, 모든 경우에 대해서 income = Low이고,
T = {+(5, 8), -(2)}가 되어, 더 이상 class의 구분이 불가능하다.
이 경우 majority를 leaf로 한다 '+'
∴ A=<M, Young, Low>는 야당성향(-)이다.
2. Example 1, 2, 3을 이용하여 multi-layer neural network에서의 backpropagation learning을
한번 수행하는 과정을 보이고, 그 결과에 따라 유권자 A=(M, 35, 2000)의 성향을 + 또는 -로
분류하시오. Neural network의 구조는 다음 그림과 같이 하고, 각 unit의 output function은
sigmoid이며, w1 = 1, w2 = -1, 나머지 weight는 모두 0.0으로 하시오. Learning rate는 10.0,
각 attribute의 값은 다음과 같이 [-1, 1]로 normalize 하여 사용하시오.
sex: Male=1.0, Female=-1.0
age: (age - 40.0) / 20
income: (income - 2500) / 2500
Initial weight:
W3, W4, W5, W6, W7, W8, W9, W10, W11 = 0
W1 = -1, W2 = 1, c = 10
example 1 : (1, 0.7, 0.4) d = 1
H1 = 1/(1+e-s) = 0.5, (s = sex * W5 + age * W6 + income * W7 + W4 = 0)
H2 = 1/(1+e-s) = 0.5, (s = sex * W8 + age * W9 + income * W10 + W11 = 0)
O = 1/(1+e-s) = 0.5, (s = H1* W1 + H2 * W2 + W3 = 0)
deltaO = (d-O) * O * (1-O) = 0.1250
deltaH1 = deltaO * W1 * H1 * (1-H1) = -0.03125
deltaH2 = deltaO * W2 * H2 * (1-H2) = 0.03125
W1 = W1 + c * deltaO * H1 = -0.3750
W2 = W2 + c * deltaO * H2 = 1.625
W3 = W3 + c * deltaO * 1 = 1.250
W4 = W4 + c * deltaH1 * 1 = -0.3125
W5 = W5 + c * deltaH1 * sex = -0.3125
W6 = W6 + c * deltaH1 * age = -0.2188
W7 = W7 + c * deltaH1 * income = -0.1250
W8 = W8 + c * deltaH2 * sex = 0.3125
W9 = W9 + c * deltaH2 * age = 0.2188
W10 = W10 + c * deltaH2 * income = 0.1250
W11 = W11 + c * deltaH2 * 1 = 0.3125
example 2 : (-1, -1, -0.52) d = 0
H1 = 1/(1+e-s) = 0.2806, (s = sex * W5 + age * W6 + income * W7 + W4)
H2 = 1/(1+e-s) = 0.4296, (s = sex * W8 + age * W9 + income * W10 + W11)
O = 1/(1+e-s) = 0.8499, (s = H1 * W1 + H2 * W2 + W3)
deltaO = (d-O) * O * (1-O) = -0.1084
deltaH1 = deltaO * W1 * H1 * (1-H1) = 0.005289
deltaH2 = deltaO * W2 * H2 * (1-H2) = 0.06417
W1 = W1 + c * deltaO * H1 = -0.9934
W2 = W2 + c * deltaO * H2 = 1.159
W3 = W3 + c * deltaO = 0.1659
W4 = W4 + c * deltaH1 * 1= -0.2129
W5 = W5 + c * deltaH1 * sex = -0.41219
W6 = W6 + c * deltaH1 * age = -0.3184
W7 = W7 + c * deltaH1 * income = -0.1768
W8 = W8 + c * deltaH2 * sex = 0.7442
W9 = W9 + c * deltaH2 * age = 0.6504
W10 = W10 + c * deltaH2 * income = 0.3495
W11 = W11 + c * deltaH2 * 1= -0.1192
example 3 : (-1, 0.25, 0.68) d = 1
H1 = 1/(1+e-s) = 0.4999, (s = sex * W5 + age * W6 + income * W7 + W4)
H2 = 1/(1+e-s) = 0.3863, (s = sex * W8 + age * W9 + income * W10 + W11)
O = 1/(1+e-s) = 0.5293, (s = H1* W1 + H2 * W2 + W3)
deltaO = (d-O) * O * (1-O) = 0.1173
deltaH1 = deltaO * W1 * H1 * (1-H1) = -0.02913
deltaH2 = deltaO * W2 * H2 * (1-H2) = 0.03223
W1 = W1 + c * deltaO * H1 = -0.4071
W2 = W2 + c * deltaO * H2 = 1.612
W3 = W3 + c * deltaO = 1.339
W4 = W4 + c * deltaH1 * 1= -0.5041
W5 = W5 + c * deltaH1 * sex = -0.1208
W6 = W6 + c * deltaH1 * age = -0.3912
W7 = W7 + c * deltaH1 * income = -0.3749
W8 = W8 + c * deltaH2 * sex = 0.4218
W9 = W9 + c * deltaH2 * age = 0.7310
W10 = W10 + c * deltaH2 * income = 0.5687
W11 = W11 + c * deltaH2 * 1 = 0.2032
A: (1, -0.25, 0.2) 에 대한 neural network의 output O = 0.8926 > 0.5
∴ A=<M, Young, Low>는 여당성향(+)이다.
3. (WEKA) 위 1, 2번에 사용된 데이터로 다음을 수행하시오.
1) ARFF 파일을 작성하시오. neural network의 경우 세가지 attribute의 타입은
모두 real로 하시오.
Decision tree:
@relation hw4
@attribute sex {M, F}
@attribute age {Y, O}
@attribute income {H, L}
@attribute class {+, -}
@data
M, O, H, +
F, Y, L, -
F, O, H, +
M, Y, H, -
F, Y, L, +
M, Y, H, -
M, O, L, +
F, Y, L, +
M, Y, L, -
Neural network:
@relation hw4
@attribute sex real
@attribute age real
@attribute income real
@attribute class {+, -}
@data
1, 0.7, 0.4, +
-1, -1.0, -0.52, -
-1, 0.25, 0.68, +
1, -0.1, -0.68, -
-1, -0.75, -1.0, +
1, -0.5, 0.52, -
1, 0.4, -0.12, +
-1, -0.4, -0.2, +
1, -0.55, -0.08, -
2) WEKA를 사용하여 decision tree (J48), neural network (multilayerPerceptron)으로
학습을 수행하여 학습결과 얻어진 모델(함수)을 보이고 모델의 정확도를 보이시오.
정확도는 9-fold cross validation을 수행하여 구하시오.
Decision tree:
Correctly Classified Instances 6 66.6667 %
Incorrectly Classified Instances 3 33.3333 %
Neural network:
Sigmoid Node 0
Inputs Weights
Threshold -1.2877454144815335
Node 2 6.336370508429555
Node 3 -3.175366852826983
Sigmoid Node 1
Inputs Weights
Threshold 1.2882612886859117
Node 2 -6.334008973456787
Node 3 3.172332454644374
Sigmoid Node 2
Inputs Weights
Threshold 0.8712521397068584
Attrib sex -3.806121360872016
Attrib age 6.859539556488592
Attrib income -1.4862723057131864
Sigmoid Node 3
Inputs Weights
Threshold -0.3446589785401386
Attrib sex 1.8621658757094555
Attrib age -3.3434289883065005
Attrib income 0.5784976831594199
Correctly Classified Instances 6 66.6667 %
Incorrectly Classified Instances 3 33.3333 %
3) 얻어진 모델에 따라 (M, 35, 2000) 의 +/- 값을 판단하시오.
(속성값이 (M, 35, 2000), 클래스 값이 ?인 데이터 하나가 있는 ARFF 파일을 만든뒤
Test options에서 supplied test set을 선택하여 만든 파일를 지정하고,
More ooptions에서 output predictions를 체크하고 실행하면 결과를 확인할 수 있음)
Decision tree:
@relation hw4-test
@attribute sex {M, F}
@attribute age {Y, O}
@attribute income {H, L}
@attribute class {+, -}
@data
M, Y, L, ?
-->
=== Predictions on test set ===
inst#, actual, predicted, error, probability distribution
1 ? 2:- + 0 *1
Neural network:
@relation hw4-test
@attribute sex real
@attribute age real
@attribute income real
@attribute class {+, -}
@data
1, -0.25, 0.2, ?
-->
=== Predictions on test set ===
inst#, actual, predicted, error, probability distribution
1 ? 2:- + 0.017 *0.983
4. (WEKA) letter.arff 데이터는 인쇄된 숫자 이미지로부터 pixel들의 분포에 대한 16가지의 속성을 추출하고 그 속성값들을 바탕으로 A ~ Z 26개 문자 중 하나를 인식하는 문제에 대한 example들이다. 이 데이터로 decision tree (J48)와 neural network (multilayer Perceptron) 학습을 수행하여 다음의 결과를 보이시오.
1) letter-test.arff 파일의 5개 데이터가 각각 무슨 문자인지 판단하시오.
(Test options에서 supplied test set을 선택하여 letter-test.arff를 지정하고,
More ooptions에서 output predictions를 체크하고 실행하면 결과를 확인할 수 있음)
=== Predictions on test set ===
inst#, actual, predicted, error, probability distribution
1 ? 8:H + 0
2 ? 1:A + *0.994
3 ? 16:P + 0
4 ? 16:P + 0
5 ? 25:Y + 0
∴ H, A, P, P, Y
2) Test options에서 percentage split을 선택하고 %값을 작은 수에서부터 변화시키면서
정확도를 확인하여 decision tree와 neural network 알고리즘의 학습 곡선을
각각 그려보시오.
'Univ Study > 인공지능' 카테고리의 다른 글
인공지능 과제4 (0) | 2010.02.15 |
---|---|
인공지능 과제3 (0) | 2010.02.15 |
인공지능 과제2 (2) | 2010.02.15 |
인공지능 과제1 (0) | 2010.02.15 |
인공지능 프로로그(Prolog) 설치파일 (0) | 2010.02.15 |