Zero Labs
Industry News / AI

The Origins of Mean Squared Error

Source · Towards AI By Wuiii

From the publisher’s feed, collected in the ZeroLabs newsroom.

Image Generated by Gemini in the light of articleIf you are working on modeling or trying to pattern out things in the world of mathematics. Then the first term you would hear is linear regression, the idea of weighing your features with a bias might look cool. However, when trying to train it i.e. to work on fitting the line in a better fashion then we can start with maybe modeling some linear phenomena. As we are into modeling, we generally need two things:1. How to define how much wrong we are? 2. How to correct ourselves?Regarding the first question, we build a function that tells us how much loss we are experiencing this quantifies how wrong we are. We then define how correct we are by trying to minimize this error. Instead of just playing with ideas, to practically implement this concept, we cannot simply use raw differences between our predictions and reality. If we did, positive and negative errors would cancel each other out, making a wildly inaccurate model look completely correct. Nor can we simply use absolute differences, as that creates sharp turns in our error calculation, making it difficult to smoothly optimize.To optimize how we model and improve our fit, we need our measure of wrongness to transform into a smooth curve. By squaring our errors, we guarantee every error stays positive while transforming the relationship into a smooth function. Thus, a valley-like error surface becomes an important criterion for improvement.We define the loss as a valley-like surface so we can locate the minimum point where our error is lowest. If you are wondering how we reach this point, that could fill a whole article on its own. For now, understand it as a step-by-step process of moving toward the minimum point — much like how you would navigate down to the bottom if you were placed on a hilly surface and asked to find the lowest spot.In simple linear regression, we start with an initial linear model that we iteratively adjust to fit the actual target function. Let these equations be defined as:The generalized error ‘e’ for a given data point is the difference between the actual output and the model’s prediction:where,So, as the error is in the form of linear equation, the square of a linear equation is a quadratic equation. Arranging as a polynomial in terms of mₑᵣᵣₒᵣ.where,Because e² is a quadratic function with respect to the parameters (m and c), it forms a smooth, convex paraboloid. Thus, a simple optimization problem to find the minima can minimize the error here. Here, again note, I am not teaching linear regression rather talking about MSE only.However, while we are iterating over multiple data points we are getting multiple error values while comparing the predicted ones with the actual outputs. In this case we take the square of each and take the mean of all these calling it a mean squared error. The mean squared error general formula is:This formula is actually deeply convex because the addition of various convex equations is also convex. As illustrated below for N residuals or errors:For N individual data points (x₁, y₁), (x₂, y₂), …, (x_N, y_N), each point generates a residual like:Substituting each squared error into the Mean Squared Error definition gives:Distributing the summation across all terms:Since cₑᵣᵣₒᵣ² is constant with respect to the summation index i,Dividing through by N:where,As shown, adding all the individual quadratics results in a single overall quadratic polynomial in terms of mₑᵣᵣₒᵣ, proving that the sum of these convex functions is also convex. This is how we improve ourselves and move further to minimize our errors.You might be still with question like… well, this is good but the assumption would actually fail because data might have be following our assumptions. That’s true. So, we do not get something which we could call a ideal fit as we see with assumptions with MSE as 0. However, we would rather get something which we could work with. Apart from this, we also use other methods to improve our performance. This post was however just give reasoning about why we go with MSE.Hope you may find this useful. It had be helpful if you correct or either share your thoughts or your emotions in comment section too. It motivates me to come up with such topics. Thanks for reading :)The Origins of Mean Squared Error was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.