금융상품 갱신 여부를 0과 1로 예측하는 딥러닝 예제
1. 딥러닝 시 필요한 라이브러리 가져오기
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense
2. 모델 생성
model = Sequential()
# 예측할 때 사용할 컬럼이 11개 이므로 input shape을 설정
model.add( Dense(units = 6, activation='relu', input_shape=(11,)) )
# 두번째 hidden layer이기 때문에 input_shape 필요없음
model.add( Dense(units=8, activation=tf.nn.relu))
# output layer는 0과 1 사이의 값을 출력해주는 sigmoid 사용
model.add( Dense(units=1, activation='sigmoid'))
3. 모델 컴파일
* 손실 함수 : binary_crossentropy
- 이진 분류 문제에서 사용 ( label이 0 또는 1을 값으로 가질 때 사용 )
# 최종 예측해야 하는 값이
# 갱신을 했는지(1) 안했는지(0) 여부를 판단하는 것이므로
# binary crossentropy 사용
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])