Now that we have the model, loss function, and optimizer function defined, train the model to learn the parameters, w, and b. To train the model, define the following global variables:
- num_epochs: The number of iterations to run the training for. With every iteration, the model learns better parameters, as we will see in the plots later.
- w_hat and b_hat: To collect the estimated w and b parameters.
- loss_epochs, mse_epochs, rs_epochs: To collect the total error value on the training dataset, along with the mse and r-squared values of the model on the test dataset in every iteration.
- mse_score and rs_score: To collect mse and r-squared values of the final trained model.
num_epochs = 1500w_hat = 0b_hat = 0loss_epochs = np.empty(shape=[num_epochs],dtype=float) ...