TITLE: Derivative of Mean Squared Error
QUESTION [6 upvotes]: 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?

REPLY [3 votes]: Since you take derivative with respect to $p$, you first take the derivative of $(y−p)^2$ and then $−p$. Finally multiply them.
So first part is  $2(y−p)$ and the second part is simply $−1$.
Therefore the derivative is  $-1 \times2\times(y-p) =−2(y−p)$