준비된 데이터는 아래와 같다.

 

import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense

model = Sequential()
model.add(Dense(units = 6, activation = 'relu', input_shape = (11,)))
model.add(Dense(units = 8, activation = tf.nn.relu))
model.add(Dense(units = 1, activation = 'sigmoid'))
model.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

input_shape는 X_train의 열 개수만큼 넣고 히든 레이어를 작성한 후 마지막을 sigmoid 활성함수로 지정한다.

손실함수는 binary_crossentropy 평가방법은 accuracy로 정한다.

model.fit(X_train, y_train, epochs = 20, batch_size = 10)
y_pred = model.predict(X_test)
y_pred = (y_pred > 0.5).astype(int)
cm = confusion_matrix(y_test, y_pred)

모델 학습시킨후 예측한 뒤 0과1로 바꿔주고 confusion_matrix를 살펴본다

+ Recent posts