FLY AI 4기 6일차: 심층학습

염지현·2024년 1월 1일

FLY AI 4기

목록 보기
7/16

6일차: 심층학습

6일차 요약

  • 오전: Linear regression 실습
  • 오후: Binary classification 실습

Linear regression: 선형회귀

모델만들기 실습

from tensorflow import keras
from keras import layers

model = keras.Sequential([
    layers.Dense(units = 6, activation='relu', input_shape = (6,)),
    layers.Dense(units=3, activation='relu'),
    layers.Dense(units=1)
])

모델 요약

모델 컴파일

model.compile(
    loss = 'mse',
    optimizer = 'adam',
    metrics = ['mse','mae']
)

모델 학습

EPOCHS = 100
BATCH_SIZE = 16

history = model.fit(
    X_train_s,
    y_train,
    batch_size = BATCH_SIZE,
    epochs=EPOCHS,
    verbose=1
)
epochs = history.epoch

plt.plot(history.history['loss'])
plt.show()
  • history를 통해 loss가 줄어드는 것을 그래프로 시각화하여 볼 수 있음

Binary classification

모델 만들기

from tensorflow import keras
from keras import layers

model = keras.Sequential([
    layers.Dense(units = 3, activation='relu', input_shape = (8,)),
    layers.Dense(units=2, activation='relu'),
    layers.Dense(units=1, activation='sigmoid')
])

모델 컴파일

model.compile(
    loss = 'binary_crossentropy',
    optimizer = 'adam',
    metrics=['accuracy']
)

모델 훈련

EPOCHS = 100
BATCH_SIZE = 16
history = model.fit(
    X_train_s,
    y_train,
    epochs = EPOCHS,
    batch_size = BATCH_SIZE,
    validation_split = 0.2,
    verbose = 1
)

0개의 댓글