# Why Cost Function for Linear Regression Is Always a Convex Shaped Function?

This diagram is from Andrew Ng course for ML/DL:

enter image description here

But isn't the cost function (least squares function) shape depends on scatter of the data ?

For example below, the minimum will be at (0,1):

enter image description here

that doesn't correspond to convex shape (if you will imagine it in 3d plot), that Andrew Ng showed above.

UPDATE

Oh, i think I understand... my example is a convex shape too, but simply shifted by coordinates, relatively to the Andrew's example.

Am i right?

• the cost function should be convex, which corresponds roughly to a "bow" shape – Tony S.F. Mar 8 '18 at 17:34
• sorry, updating question – uptoyou Mar 8 '18 at 17:39

$$\frac{1}{2} \left\| X \theta - y \right\|_{2}^{2}$$
Which is a Linear Regression Problem with the Least Squares cost function which is a Convex Function of $\theta$.
• The notation $\left\| \cdot \right\|$ stands for norm. So the ${\left\| \cdot \right\|}_{2}$ stands for the ${L}_{2}$ norm and ${\left\| \cdot \right\|}_{2}^{2}$ is the ${L}_{2}$ norm squared. – Royi Oct 14 '18 at 6:04