early stopping in keras

Purpose: to prevent overfitting

# early stoppping
from keras.callbacks import EarlyStopping
early_stopping = EarlyStopping(monitor='val_loss', patience=50, verbose=2)
# Training
history = model.fit(train_X, train_y, epochs=300, batch_size=20, validation_data=(test_X, test_y), verbose=2, shuffle=False, callbacks=[early_stopping])
monitor:  the amount to be monitored, val_loss, val_acc
patience:  when early stop is activated (if it is found that the loss has not decreased compared to the previous epoch training), the training will be stopped after patience epochs
verbose:  information display mode
mode: 'auto', One of 'min', 'max' , train in min mode, stop training if detections stop falling. In max mode, the training is stopped when the detection value no longer rises.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324946339&siteId=291194637