반응형
overfitting & underfitting
overfitting (과대적합) / underfitting(과소적합)
오버핏팅이란 학습한 결과가, 학습에 사용된 데이터와 거의 일치하여,
새로운 데이터가 들어왔을 때, 예측이 틀려버리는 상태
새로운 데이터에 일반화되기 어렵다.
언더핏팅은 그 반대다.
예시 코드
def build_model() :
model = tf.keras.models.Sequential()
model.add( tf.keras.layers.Flatten() )
model.add( tf.keras.layers.Dense( 128, 'relu'))
model.add( tf.keras.layers.Dense( 10, 'softmax'))
model.compile('adam', loss = 'sparse_categorical_crossentropy', metrics=['accuracy'])
return model
model = build_model()
epoch_history = model.fit(training_images, training_labels, epochs=30, validation_split = 0.2)

plt.plot( epoch_history.history['loss'] )
plt.plot( epoch_history.history['val_loss'] )
plt.legend( [ 'train loss', 'validation loss' ] )
plt.show()

plt.plot( epoch_history.history['accuracy'] )
plt.plot( epoch_history.history['val_accuracy'] )
plt.legend( [ 'train accuracy', 'validation accuracy' ] )
plt.show()

반응형
'Deep Learning > Tensorflow' 카테고리의 다른 글
| Tensorflow - validation_data 파라미터 사용 법 (0) | 2022.06.14 |
|---|---|
| Tensorflow - callback class를 이용해서, 원하는 조건이 되면 학습을 멈추게 하는 코드 (0) | 2022.06.13 |
| Tensorflow - softmax로 나온 결과를, 레이블 인코딩으로 바꾸는 방법 (0) | 2022.06.13 |
| Tensorflow - 분류의 문제에서 loss 셋팅하는 방법 (0) | 2022.06.13 |
| Tensorflow - activation function [ softmax ] (0) | 2022.06.13 |