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

2.5k Views Asked by At

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?

1

There are 1 best solutions below

4
On BEST ANSWER

Because the cost function is given by:

$$ \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 $.