본문 바로가기

Deep Learning/Tensorflow

Tensorflow - overfitting & underfitting

반응형
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()

 

 

반응형