# Test score bigger than Train score in Linear Regression

I'm new to ML and I'm trying to create a linear regression model. My data consist of 100 samples with 4 features each. This is my humble code

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=80)

reg = LinearRegression()
reg.fit(X_train, y_train)
score_test = reg.score(X_test, y_test)
score_train = reg.score(X_train, y_train)
print("Train Score is :", score_train)
print("Test Score is :", score_test)


The problem is that the score in Test set (0.97) is way bigger than the score in Train set (0.71). How we can explain this?

Have you perhaps misinterpreted what "score" is meant to be doing? From the sci kit learn website:

.score( ) Returns the coefficient of determination R^2 of the prediction

It is not looking at the accuracy measure of your regression, but the R^2 value of your regression fit of your linear regression on your training data set. It doesn't make sense to use it again on the testing data (that's not how R^2 is supposed to work).

• But shouldn't the R^2 score in the train set be bigger than R^2 score in the test set?? – Don Aug 28 '19 at 18:35
• Please refer to this anawer. I think it may help in your understanding stats.stackexchange.com/a/320519/117574 – pche8701 Aug 28 '19 at 18:50
• Also imagine if your test set were two data points, and these two points completely lie on your model regression line by chance. It would have an R^2 value of 1. – pche8701 Aug 28 '19 at 18:52
• Also if you are happy with my answer please dont forget to mark it as accepted by using the tick :) – pche8701 Aug 28 '19 at 18:53