# Mean squared error > The average loss per example when L2 loss is used. Calculate MSE as follows:[^1] The average loss per [example](https://wiki.g15e.com/pages/Example%20(machine%20learning.txt)) when [L2 loss](https://wiki.g15e.com/pages/L2%20loss.txt) is used. Calculate MSE as follows:[^1] 1. Calculate the L2 loss for a [batch](https://wiki.g15e.com/pages/Batch%20(machine%20learning.txt)). 2. Divide the L2 loss by the number of examples in the batch. Mean Squared Error is a popular training [optimizer](https://wiki.g15e.com/pages/Optimizer%20(machine%20learning.txt)), particularly for [linear regression](https://wiki.g15e.com/pages/Linear%20regression.txt).[^1] ## Formula $$ MSE = \frac{1}{N}\sum_{i=0}^{N} (y_i - \hat{y}_i)^2 $$ where: - $n$ is the number of [examples](https://wiki.g15e.com/pages/Example%20(machine%20learning.txt)). - $y$ is the actual value of the [label](https://wiki.g15e.com/pages/Label%20(machine%20learning.txt)). - $\hat{y}$ is the [model](https://wiki.g15e.com/pages/Model%20(machine%20learning.txt))'s [prediction](https://wiki.g15e.com/pages/Prediction%20(machine%20learning.txt)) for $y$. ## See also - [Mean absolute error](https://wiki.g15e.com/pages/Mean%20absolute%20error.txt) - [Root mean squared error](https://wiki.g15e.com/pages/Root%20mean%20squared%20error.txt) ## Footnotes [^1]:https://developers.google.com/machine-learning/glossary#MSE