We created the model architecture.
The input layer, the hidden layers and the output layer.
Now let's train our model here.
Create a new cell and let's set up early stopping to prevent overfitting.
In the previous videos we learned how to use Model.fit function to train the model.
But in this example we're going to use a new thing called early stopping.
Also we're going to use Model.fit function.
But I'm going to use something called early stopping.
Early stopping equals to Tf.keras dot callback dot early stopping.
Pass the monitor equals to val loss.
Patients 20 and restore best weights equals to true.
What does this code do?
Early stopping automatically halts training when the model stops, improving on validation data.
Preventing overfitting to the training set.
So if you have large data and your model, for example, get trained with the first 200 epochs and you
specified, for example, 500 epochs.
Why you should make unnecessary 300 epochs and get the same results.
So here the early stopping to prevent overfitting to the training set.
When the model stops improving on validation data, it's very important we're going to depend on the
Mae and MSE.
We're going to see the results here in this video.
And you should see how early stopping is important to prevent memory leakage, overfitting, um, resource
heating and memory.
Okay, so there are a lot of things we can prevent using the early stopping.
Don't worry.
We're going to show you, uh, to see all those in the next couple of minutes.
Monitor.
Tell us what to watch.
Tracks the validation loss during the training.
So go and see the value.
Val loss.
You can also use val accuracy.
Loss accuracy.
So you can you can specify accuracy.
You can specify val accuracy.
But for this example we're going to focus on val loss val loss is preferred for regression tasks.
Patience equals to 20.
How long to wait.
Number of epochs with no improvement before stopping.
And if the validation loss doesn't improve for 20 consecutive epochs.
Training stops balanced to best weights and crucial feature reverts model weights to the apex with the
best performance.
Without this, you'd get weights from the final, possibly overfitted epoch.
Ensures you get the optimal model from training.
Now let's start training the model so history equals to model dot fit.
We use this fit function to train the model we used in the previous videos and previous sections.
Passing the exit train scaled.
This is very important guys.
So here we need to pass the scaled because we talked about feature scaling.
And here x train scaled parameter is passed passed Y train apex 1000.
You can make it 200 400, 300.
I'll start 200 and see the parameters.
If there is a stop early stop.
So there is no need to use 1000.
Okay, so let me start with 200 and see the results.
Validation split 0.2.
Batch size 32 callbacks early stopping.
So I'm gonna use this early stopping with the defined parameters here.
And set the verbose equals to one.
Let's click run and start training our model.
Don't worry we're going to analyze all the results.
And there we go guys.
We trained our model.
But if you notice we didn't complete the 200 epochs.
We stopped at 169 epoch okay so let me study those parameters.
Loss and Ma are very low values is 7.15.
Val e 1.9 and then Ms. 7.1.
If we go up for the first epoch, scroll up.
We see that those values were high.
So as we go down, those values becomes very small become very small.
Okay.
So as we see they are decreasing until we get the same results and there's no improvement if we continue
the epochs.
So for this purpose we used the early stop.
Okay.
So go and train the model whenever you see there is no improvement.
Stop this training.
Okay.
This is how we train the model and how we use the early stopping feature.