Smoothing 과 Log 연산을 사용했을 때 다른 결과가 나옵니다.

18.04.26 11:12 작성 조회수 106

0

안녕하세요.

강의 잘 듣고 있습니다.

2_german_credit_application 따라하다가 Smoothing과 log를 적용해 보았는데,

결과가 원래와 다르게 나옵니다.

아래 코드입니다. 혹시 제가 실수한 곳이 있나요.

몇 시간이나 이것 저것 바꾸어 보았지만 찾지 못해서 질문드립니다.

고맙습니다.

import pandas as pd

import numpy as np

df = pd.read_csv('./fraud.csv', sep=',')

del df['ID']

y_data = df['Fraud'].as_matrix()

x_df = pd.get_dummies(df[['History', 'CoApplicant', 'Accommodation']])

x_data = x_df.as_matrix()

ix_y_is_true = np.where(y_data == True)[0]

ix_y_is_false = np.where(y_data == False)[0]

p_y_is_true = len(ix_y_is_true) / len(y_data)

p_y_is_false = len(ix_y_is_false)/ len(y_data)

# Smoothing...

k = 2

p_x_when_y_is_true_sm = (np.sum(x_data[ix_y_is_true], axis=0) + k) / (len(ix_y_is_true) + k * 2)

p_x_when_y_is_false_sm = (np.sum(x_data[ix_y_is_false], axis=0) + k) / (len(ix_y_is_false) + k * 2)

# Test

x_test = [0,1,0,0,0,1,0, 0,1,0]

p_true = np.log(p_y_is_true) + np.dot(x_test, np.log(p_x_when_y_is_true_sm))

p_false = np.log(p_y_is_false) + np.dot(x_test, np.log(p_x_when_y_is_false_sm))

print('p_true > p_false :', p_true > p_false)

답변 2

·

답변을 작성해보세요.

0

감동기님의 프로필

감동기

질문자

2018.04.26

강의하신 내용에서는 p_true < p_false가 됩니다만 제가 올려드린 코드에서는 p_true > p_false가 됩니다.
x_test에 대한 추정값이 다르게 나옵니다.
Smoothing Factor 조정하니 결과가 다르게 나오네요, k를 1로 주면 강의하신대로 p_true < p_false인 결과가 나옵니다.
좋은 강의 항상 감사드립니다.

0

원래 결과와 다르게 나왔다는게? 값이 변경된건가요? 아니면 class가 변경된건가요?