12

I'm studying with a book and I'm at the Linear Regression part. The author is showing that we have to calculate the derivative of each part of the equation that leads to the loss.

But he's using the MSE to calculate the loss and so, I tried to calculate the derivative of MSE:

the derivative of $ (y-p)^2 $ with respect to y (the target) is equal to $2(y-p)$ but in the book it is written $-1*(2(y-p))$ which is simplified as $-2(y-p)$. Why do I have different values ? Where is this $-1$ coming from?

Michael
  • 263

1 Answers1

12

We are to take derivative with respect to $p$ (and not $y$). We note that MSE is a composition of 2 differentiable functions: $f(g(p))$ where $f(z)$ is $z^2$ and $z$ is $g(p)$ and $y-p$. Therefore, we will resort to the chain rule, by first taking the derivative of $f(z)$ and multiplying it by the derivative of $g(p)$. Namely,

$f'(z)$ is $2(z)$ and $g'(p)$ is $−1$.

We plug and chug and the derivative results in: $2(y-p)\times-1 =>−2(y−p) => 2[-1(y-p)] => 2(p - y)$

Sam Oz
  • 121