C.W.K.
Stream
Lesson 05 of 08 · published

model.fit()

~8 min · training

Level 0Keras 도제
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

학습 한 줄: history = model.fit(x, y, epochs=10, batch_size=32, validation_split=0.1, callbacks=[...]). history 가 loss / metric 의 epoch 별 list 들어있는 객체. 그래프 그릴 때 history.history['loss'].

data 가 큰 경우 generator 또는 tf.Dataset / torch.DataLoader 도 OK — fit() 이 알아서 처리. 학습 도중 멈추려면 callback (EarlyStopping, ModelCheckpoint) 활용. fit() 한 호출이 학습 전체야.

Code

history = model.fit(
    x_train, y_train,
    epochs=20,                 # Number of passes through the data
    batch_size=32,              # Samples per gradient update
    validation_split=0.2,       # Use 20% of training data for validation
    # OR: validation_data=(x_val, y_val),
    class_weight={{0: 1.0, 1: 5.0}},  # For imbalanced data
    callbacks=[...],              # List of callback instances
)

# history.history contains loss/metric values per epoch
print(history.history["loss"])         # [0.83, 0.54, 0.41, ...]
print(history.history["val_accuracy"]) # [0.72, 0.81, 0.85, ...]

External links

Exercise

MNIST 10 epoch 학습. history.history 저장. training/validation loss, accuracy 를 두 subplot 에 그려. validation loss 가 다시 올라가기 시작하는 epoch 식별.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.