# How do you calculate the training error and validation error of a linear regression model?

I have a linear regression model that I've implemented using Gradient Descent and my cost function is a Sum of Squares Error function. I've split my full dataset into three datasets, a training set, a validation set, and a testing set. I am not sure how to calculate the training error and validation error (and the difference between the two).

Is the training error the Residual Sum of Squares error calculated using the training dataset? Is the validation error the Residual Sum of Squares error calculated using the validation dataset? What is the test set for exactly (I've learned the model using the training set, from the textbooks I've read I think this is the set to use to learn the model)?

Any help in clearing up these points is much appreciated.

• so if I was doing this in Python, and let's say I had 90 data-points in the training data set, then is this the correct code for the training error? y_predicted = f(X_train, theta) training_error = 0 for i in range(90): out = y_predicted[i] - y_train[i] out = out*out training_error+=out training_error = training_error/2 print('The training error for this regression model is:', training_error) Apr 25, 2020 at 11:26