pythonmachine-learningkeraslstmearly-stopping

Keras LSTM - Why my Earlystopping function didn't work?


I am new to deep learning and Keras, and try to make my model classification more accurate. Because there are only 75 data, so I separated 60 for training & 15 for validation (80/20), so it's easy to overfitting. I have tried to add more layers, more units, reducing layers, units, increasing and decreasing learning rate, etc for better performance.

From previous runs, I know my val_acc is decreasing to 0.8 in about 100-150 epochs, so I want to stop the training at that time to avoid the decrease.

Before using earlystopping

I currently train with a batch size of 5, each fit is made of 350 epochs. Now I want to use the Earlystopping to stop at the closest training & validation accuracy epoch but did not succeed yet.

I tried to set the monitor 'val_acc' at least reaches the baseline value is 0.8, and then add a min_delta = 0.01 in the expectation that this rule would only be applied after the baseline was reached, however that did not help. After adding the early stopping function, why does it stop so early without reaching the baseline? And every time I changed the patience, the training would stop at "THAT" patience.

after adding earlystopping Here is my code.

#early stopping
from Keras.callbacks import EarlyStopping
early_stopping= keras.callbacks.EarlyStopping(monitor='val_acc', min_delta=0.01, patience=5, verbose=0, mode='max', baseline=0.8, restore_best_weights=False)

train_history =model.fit(X_train, train_Label,batch_size=5,
                         epochs=300,verbose=2,callbacks=[early_stopping],
                         validation_split=0.2)

Why does it stop so early without reaching the baseline? Any reason for this? How should I adjust the function to satisfied my expectations? Or are there any good practices that can be applied to get the highest validation accuracy?

Thank you!


Solution

  • Your model is built to stop training if the baseline accuracy isn't reached by the time your number of patience is reached. Baseline is for when you dont want training to continue if things arent going to plan.

    See here for a simple explanation.

    Remove baseline and your model will stop when required. Also in your code snippet you've got delta = 0, just fyi.