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.


1 Answer 1


Yes. Yes. The test set is used to get an unbiased measure of the performance of your model. This is explained in many sources, better than I can explain here; I won't try to repeat them. See, e.g., https://en.wikipedia.org/wiki/Training,_validation,_and_test_sets, https://stats.stackexchange.com/a/104750/2921, or standard textbooks.

  • $\begingroup$ 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) $\endgroup$ Commented Apr 25, 2020 at 11:26
  • $\begingroup$ @AnthonyKubeka, sorry, coding questions are off-topic here, and comments shouldn't be used to ask new questions. Comments exist to help people improve their answer. If you have a follow-up question, you can ask a new question if it is on-topic (if not here, maybe you can find another site to ask). $\endgroup$
    – D.W.
    Commented Apr 25, 2020 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.