From 65ce172f3f496675b9749ce636a810489475bfa5 Mon Sep 17 00:00:00 2001 From: tcsenpai Date: Wed, 11 Sep 2024 00:48:56 +0200 Subject: [PATCH] Implement early stopping to enhance model accuracy and prevent overfitting - Add EarlyStopping callback to LSTM and GRU model training - Monitor validation loss with patience of 10 epochs - Automatically stop training when performance plateaus - Restore best weights found during training --- goldigger.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/goldigger.py b/goldigger.py index 6bd65f8..131520d 100644 --- a/goldigger.py +++ b/goldigger.py @@ -139,7 +139,9 @@ def walk_forward_validation(X, y, model, n_splits=5): model.fit(X_train_2d, y_train) predictions = model.predict(X_test_2d) elif isinstance(model, Sequential): - model.fit(X_train, y_train, epochs=100, batch_size=32, verbose=0) + early_stopping = EarlyStopping(monitor='val_loss', patience=10, restore_best_weights=True) + model.fit(X_train, y_train, epochs=100, batch_size=32, verbose=0, + validation_split=0.2, callbacks=[early_stopping]) predictions = model.predict(X_test).flatten() all_predictions.extend(predictions)