Introduction
In our previous lesson, we established a crucial dividing line in the world of optimization: the difference between convex and non-convex functions. You learned that for convex, "bowl-shaped" functions, any local minimum is guaranteed to be the global minimum, making optimization a reliable process. We concluded by stating that linear regression with Mean Squared Error (MSE) loss falls into this "nice" category.
Today, we will dissect the why. This lesson moves from the what to the how, analyzing the mathematical structure of the MSE loss function itself. You will see precisely how the formula for MSE gives rise to a specific geometric shape—a convex paraboloid—and why this shape is the reason gradient descent can be trusted to find the single best solution for a linear model. This understanding forms the bedrock of classical machine learning and provides a vital contrast to the complex, non-convex landscapes you'll encounter in deep learning.
From Error Calculation to a Loss Surface
Let's begin by re-examining the Mean Squared Error (MSE) loss function. At its core, it's a way to aggregate the errors from every data point in our training set into a single number that tells us how badly our model is performing.
For a linear model with two parameters, a weight and a bias , the prediction for a given data point is . The error, or residual, for that point is the difference between the actual value and our prediction.
The MSE loss, , is the average of the squares of all these errors:
The most important part of this equation is the exponent: the square. Everything about the shape of the loss surface for linear regression flows from this simple mathematical operation. Any error, whether positive or negative, becomes a positive value when squared. This ensures that all errors contribute to the loss and that larger errors are penalized much more heavily than small ones.
To build intuition for how this formula creates a shape, let's watch how it's constructed, one parameter at a time.
Gradient Descent, Step-by-Step
This StatQuest video by Josh Starmer provides an excellent, step-by-step visualization of how the loss function is built from the sum of squared residuals.
First, watch the introduction to see how the sum of squared residuals is defined as the loss function for linear regression (the setup). Next, focus on how the loss changes as we vary just one parameter, the intercept. This generates a 2D parabola (a 2D plot). This is the simplest version of our loss surface. Finally, see how this extends to two parameters (intercept and slope), creating a 3D surface (the 3D graph). This 3D "bowl" is the object we are analyzing.
The Paraboloid Shape of MSE
As the video demonstrated, when we plot the loss as a function of the two parameters and , the resulting surface is a paraboloid. This is the 3D-analogue of the 2D parabola. For a model with more than two parameters, the loss surface is a higher-dimensional version of this, often called a hyper-paraboloid.

Why does the MSE formula produce this specific shape?
-
The Quadratic Nature: The loss function is a quadratic function with respect to its variables, and . If you were to expand the squared term, you would get terms involving , , , , and . This is the general form of a quadratic expression in two variables, which always graphs as a paraboloid.
-
The Sum of Convex Functions: We can also arrive at this conclusion using a powerful property we touched on in the last lesson. A simple function like is convex. It turns out that:
- The sum of two or more convex functions is also convex.
- Scaling a convex function by a positive constant preserves its convexity.
Our MSE loss function is a sum of many individual squared error terms, , each scaled by . Each of these individual terms is a convex paraboloid. By adding them all together, we are essentially summing up a set of convex functions. The result is another, more complex, but still perfectly convex paraboloid.
The following resource provides a great overview and visualization of this concept.
Linear regression: Gradient descent | Machine Learning
This article from Google's Machine Learning Crash Course clearly explains the link between the linear model, its loss function, and the guarantee of finding a global minimum.
First, read the page summary at the top for a quick overview. Then, scroll down and focus on the section Convergence and convex functions. Pay close attention to the 3D graphs and how they map the path of gradient descent onto the convex loss surface. This section explicitly states the key takeaway: "The loss functions for linear models always produce a convex surface."
The Guarantee of a Global Minimum
Now we can connect all the pieces.
- The MSE loss function for linear regression is mathematically a quadratic function of the model's parameters.
- This quadratic nature gives the loss surface the shape of a convex paraboloid—a perfect, high-dimensional bowl.
- As we know, a defining feature of a convex function is that any local minimum is also the global minimum.
- Therefore, when we apply an optimization algorithm like gradient descent to this surface, it is guaranteed to find the single set of parameters that corresponds to the lowest possible loss.
There are no other valleys for the algorithm to get stuck in. This is why linear regression is considered a "solved" problem in machine learning. Unlike training a neural network, where the final result can depend heavily on the random starting weights, training a linear regression model will always yield the same optimal solution, regardless of where the optimization starts.
For a more rigorous confirmation, we can use a mathematical tool called the Hessian matrix, which is a matrix of all the second-order partial derivatives of a function. A function is convex if and only if its Hessian matrix is positive semi-definite everywhere. While we will explore these concepts later in the course, the key result for MSE is shown in the following resource.
Convex vs Non-Convex Optimization | TensorTonic
This article from TensorTonic provides a concise, formal proof of why MSE loss is convex.
Read the section titled "The Hessian Test for Convexity". The critical insight is that the Hessian matrix for the MSE loss is H=2X^TX, where X is our data matrix. This matrix, known as a Gram matrix, is always positive semi-definite, which formally proves that the MSE loss function is convex.
This Hessian test is the mathematical seal of approval on the intuition we've built. It confirms that the "bowl shape" isn't just a convenient analogy; it's a direct and provable consequence of the mathematics of Mean Squared Error.
Conclusion
In this lesson, you've moved from observing that the linear regression loss surface is convex to analyzing precisely why that is. This analysis forms a complete chain of reasoning that is fundamental to understanding machine learning optimization.
Key Takeaways:
- The Mean Squared Error (MSE) loss function is a sum of squared terms, making it a quadratic function of the model's parameters ( and ).
- The graph of this quadratic function is a paraboloid—a high-dimensional bowl shape.
- A paraboloid is a convex function. This can be understood intuitively by its shape, or proven more formally by noting that MSE is a sum of convex functions, or by using the Hessian matrix test.
- Because the loss surface is convex, gradient descent is guaranteed to converge to the single global minimum. This makes the optimization of linear regression robust and predictable.
We now have a solid theoretical foundation. We understand the landscape (the loss surface), the compass (the gradient), and the guarantee of reaching our destination (the global minimum). In the next lesson, we will put this all into practice by tracing the gradient descent algorithm itself, step by step, and exploring the crucial role of the hyperparameter that controls our step size: the learning rate.