(This question may be more about Math in general but I have a specific context in mind and hence am asking this here as opposed to math.stackexchange)

I'm going through Andrew Ng's lecture notes on Machine Learning.

While deriving the update rule for linear regression, the cost function's derivative is set to 0.

I understand the cost function needs to be minimized. But setting the derivative as 0 means either you're considering the maxima, or the minima. So my question is:

  1. How can we be sure that setting the derivative to zero in this case will lead to considering the minima and not the maxima?

(I'm not sure, but my guess is that it's because we already somehow know that the cost function is convex and will only have a minima and no maxima? In that case I guess I'd want to ask:

  1. a. How can you tell if the function is convex or concave?

    b. And also, if the function is neither convex nor concave, then how do we figure if setting the derivative to zero leads to a maxima or a minima?)

EDIT: Another follow-up question. On the same notes, under 'Another algorithm for maximizing L(theta), we are introduced to Newton's method to find the minimum of a function. And this is used to find the minimum of the derivative of the likelihood. There's a self exercise in the notes that says this:

Something to think about: How would this change if we wanted to use Newton’s method to minimize rather than maximize a function?

And in the lecture here between (16:00 and 16:40) Prof. Ng mentions that this wouldn't change at all. So, my question remains, how would we know if we're considering the maximum of the function or the minimum?



1 Answer 1


You didn't specify the loss (or cost) function, so assuming it is the usual sum of square of residuals. That is a quadratic function, it cannot be negative, so is convex. That means it has a minimum (unique if there is no linear dependencies among predictors), but not a maximum. So setting the derivative to zero will find a minimum.

Your other question is how to know the loss function is convex. We can just calculate the Hessian matrix, and note that it is positive (semi)definite. The necessary calculus can be found here: Least squares: Calculus to find residual minimizers?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.