I'm working through Python Machine Learning myself and am currently on the chapter on Training a logistic regression model. In that book, the author calculates the partial derivative of a sigmoid function:
$$\frac{\partial}{\partial{z}}\phi(z) = \frac{\partial}{\partial{z}}\left(\frac{1}{1 + e^{-z}}\right) = \frac{1}{(1 + e^{-z})^{2}}e^{-z} = \frac{1}{1 + e^{-z}}\left(1 - \frac{1}{1 + e^{-z}}\right)$$
I don't understand the last two steps, how:
$$\frac{1}{(1 + e^{-z})^{2}}e^{-z} = \frac{1}{1 + e^{-z}}\left(1 - \frac{1}{1 + e^{-z}}\right)$$
Could someone please explain?
It's easier to see if you do it right to left:
$$\frac{1}{1 + a}\left(1 - \frac{1}{1 + a}\right) = \frac{1}{1+a} - \frac{1}{(1+a)^2} = \frac{1+a}{(1+a)^2} - \frac{1}{(1+a)^2} = \frac{1+a-1}{(1+a)^2} = \frac{1}{(1+a)^2}a $$ with $a=e^{-z}$.