# Mse calculation in Linear regression

Screen Link for linear regression: https://app.dataquest.io/m/235/the-linear-regression-model/6/making-predictions
Screen link for K-Nearest Neighbors: https://app.dataquest.io/m/140/multivariate-k-nearest-neighbors/8/calculating-mse-using-scikit-learn

Why on linear regression when we calculate mse whe use mse = mean_squared_error(predictions, test[target]) but on K-Neares Neighbors we used mse = mean_squared_error(test['target'], predictions)

I mean according to the sklearn documentation when we use mean_squared_error the arguments are y_true (correct target values) and y_pred (Estimated or predicted target values)

1 Like

Good observation.

But the difference in use really doesn’t matter. The MSE is given by -

Whether you calculated it as

(y_i - \hat{y_i})^2 = (predictions - test[target])^2

or as

(\hat{y_i} - y_i)^2 = (test[target] - predictions)^2

The result would be the same since you square the difference.

We can say that they should be consistent about this, but it’s not that big of an issue with MSE as per me. You can provide feedback to them for this using the Contact Us button in the top-right of this page if you’d like to.

1 Like

Thanks @the_doctor! I realized that a little bit later when i was reviewing my notes  1 Like