Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to comprehend the derivative of the cost function in linear regression involving Ridge regularization, the equation is:

$$L^{\text{Ridge}}(\beta) = \sum_{i=1}^n (y_i - \phi(x_i)^T\beta)^2 + \lambda \sum_{j=1}^k \beta_j^2$$

Where the sum of squares can be rewritten as:

$$L^{}(\beta) = ||y-X\beta||^2 + \lambda \sum_{j=1}^k \beta_j^2$$

For finding the optimum its derivative is set to zero, which leads to this solution:

$$\beta^{\text{Ridge}} = (X^TX + \lambda I)^{-1} X^T y$$

Now I would like to understand this and try to derive it myself, heres what I got:

Since $||x||^2 = x^Tx$ and $\frac{\partial}{\partial x} [x^Tx] = 2x^T$ this can be applied by using the chain rule:

\begin{align*} \frac{\partial}{\partial \beta} L^{\text{Ridge}}(\beta) = 0^T &= -2(y - X \beta)^TX + 2 \lambda I\\ 0 &= -2(y - X \beta) X^T + 2 \lambda I\\ 0 &= -2X^Ty + 2X^TX\beta + 2 \lambda I\\ 0 &= -X^Ty + X^TX\beta + 2 \lambda I\\ &= X^TX\beta + 2 \lambda I\\ (X^TX + \lambda I)^{-1} X^Ty &= \beta \end{align*}

Where I strugle is the next-to-last equation, I multiply it with $(X^TX + \lambda I)^{-1}$ and I don't think that leads to a correct equation.

What have I done wrong?

share|cite|improve this question
up vote 3 down vote accepted

You have differentiated $L$ incorrectly, specifically the $\lambda ||\beta||^2$ term. The correct expression is: $\frac{\partial L(\beta)}{\partial \beta} = 2(( X \beta - y)^T X + \lambda \beta^T)$, from which the desired result follows by equating to zero and taking transposes.

share|cite|improve this answer
Thanks, I had this intuition already, that I can rewrite the second sum to $\lambda||\beta||^2$, for what soever reason I dropped it. I think you forgot a minus in there: $$2(( X \beta - y)^T (-X) + \lambda \beta^T)$$ Since the inner derivative of $X \beta - y$ is $-X$, isn't it? – Mahoni Jul 2 '12 at 13:58
The signs are correct. – copper.hat Jul 2 '12 at 14:56
ah I see that now, thanks – Mahoni Jul 2 '12 at 15:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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