Welcome back.
In our model we have nine features cylinders displacement.
Horsepower.
Weight.
Acceleration.
Model year one, two and three.
Now those are the features that the input layer takes as parameters and as features.
Also in the hierarchy of our model we have hidden layer number one with 64 neurons learning complex
patterns.
Then we have another layer, another 64 neurons called hidden layer number two that learn more patterns.
And then we have the output layer which is the mileage and the mpg.
Okay.
We talked about this hierarchy in the previous videos.
Now let's code.
Let's create a function that creates a reusable model that follows this hierarchy.
We have input layer hidden layer number one, hidden layer number two and the input output layer under
the feature scaling.
Here we need to start building the neural network and build the model architecture.
New code.
Let's start defining a new function.
Def build model.
And to build a model we start with model equals to TensorFlow Keras dot sequential.
And we talked about this in the previous videos.
But don't worry we're going to lecture it.
This is the first layer.
This is the input layer.
So here let me make it as input layer.
We have TF dot dot layers dot dance.
We are creating a dense layer.
So this code means that we are going to create a TensorFlow layer a dense layer 64 neurons first hidden
layer with 64 units and activation ReLU.
ReLU introduces non-linearity returns maximum zero and x.
So here we have nonlinear.
The input shape automatically adapts to the number of feature in scaled data.
We can use train X train keys, but I prefer using the exit train X train scaled.
We we used the scaled.
We're going to use the scaled data.
So here get the shape and pass the parameter one.
So this will automatically adapt to number of feature in scaled data.
So we are using the scaled data not the exit train.
Please pay attention guys.
Don't use X train data.
Use the exit train underscore scaled okay.
Because we uh we introduced the feature scaling in the uh, previous videos.
And we talked about exit train scaled okay.
So our data now becomes X train scaled.
We need to deal and train our model with this trained and scaled data.
The second layer we need to create is the hidden layer.
So hidden layer number one we start with tf dot dot layer dot dense.
In order to create any layer we start with tensorflow.keras dot layers dot dense 64 activation ReLU
and another hidden layer df dot dot layer dot dense.
Here we can use not dense layer.
We can use drop out 0.2.
Why we don't use dense because we need to prevent overfitting and dropout 0.2 randomly drops 20% of
neurons during training to prevent overfitting.
So here we have 20% for the training data, for the testing data.
And here we set the randomly drops 20% of neurons during training to prevent overfitting.
The third and or the fourth and last layer is the output layer.
So output layer.
How to create it.
Start with df dot.
Dot layer.
Dot dense equals to one one neuron for regression and no activation.
So here one neuron okay so we have only one neuron for regression and no activation.
Don't miss to close this sequential.
So this is our um our sequential.
How to create the model layers.
We start by Keras tf.keras dot sequential.
This is the function used for creating the the layers.
We created the input layer with one with 64 neurons activation, ReLU and input shape.
We use the scaled trained x.
Then we create the hidden layer number one.
We create the hidden layer number two and the output layer.