Derivation of change of variables of a probability density function? In the book pattern recognition and machine learning (formula 1.27), it gives
$$p_y(y)=p_x(x) \left | \frac{d x}{d y} \right |=p_x(g(y)) | g'(y) |$$
where $x=g(y)$, $p_x(x)$ is the pdf that corresponds to $p_y(y)$ with
respect to the change of the variable. 
The books says it's because that observations falling in the range $(x, x + \delta x)$ will, for small values of $\delta x$, be transformed into the range $(y, y + \delta y)$.
How is this derived formally?

Update from  Dilip Sarwate 
The result holds only if $g$ is a strictly monotone increasing or decreasing function.

Some minor edit to L.V. Rao's answer
$$  \begin{equation}
    P(Y\le y) = P(g(X)\le y)=
    \begin{cases}
      P(X\le g^{-1}(y)), & \text{if}\ g \text{ is monotonically increasing} \\
      P(X\ge g^{-1}(y)), & \text{if}\ g \text{ is monotonically decreasing}
    \end{cases}
  \end{equation}$$
Therefore if $g$ is monotonically increasing
$$F_{Y}(y)=F_{X}(g^{-1}(y))$$
$$f_{Y}(y)= f_{X}(g^{-1}(y))\cdot \frac{d}{dy}g^{-1}(y)$$
if monotonically decreasing
$$F_{Y}(y)=1-F_{X}(g^{-1}(y))$$
$$f_{Y}(y)=- f_{X}(g^{-1}(y))\cdot \frac{d}{dy}g^{-1}(y)$$
$$\therefore f_{Y}(y) = f_{X}(g^{-1}(y)) \cdot \left | \frac{d}{dy}g^{-1}(y) \right |$$
 A: Suppose $X$ is a continuous random variable with pdf $f$.
Let $Y=g(X)$, where $g$ is a monotonic function.
The function $g$ could be either monotonically increasing or monotonically decreasing. If $g$ were monotonically increasing, then the pdf of $Y$  is obtained as follows:
\begin{eqnarray*}
P(Y\le y) &=& P(g(X)\le y)\\
&=& P(X\le g^{-1}(y))\\
or\;\;F_{Y}(y)&=& F_{X}(g^{-1}(y)),\quad \mbox{by the definition of CDF}\\
\end{eqnarray*}
If $g$ instead were monotonically decreasing, then we would have to swap the inequality signs, since $g^{-1}$ is also monotically decreasing (see here):
\begin{eqnarray*}
P(Y\le y) &=& P(g(X)\le y)\\
&=& P(X\ge g^{-1}(y))\\
or\;\;F_{Y}(y)&=& 1-F_{X}(g^{-1}(y)),\quad \mbox{by the definition of CDF}\\
\end{eqnarray*}
By differentiating the CDFs on both sides w.r.t. $y$ and using the chain rule, we get the pdf of $Y$.
If the function $g$ is monotonically increasing, then the pdf of $Y$ is given by
\begin{equation*}
f_{Y}(y)= f_{X}(g^{-1}(y))\cdot \frac{d}{dy}g^{-1}(y)
\end{equation*}
and other hand, if it is monotonically decreasing, then the pdf of $Y$ is given by
\begin{equation*}
f_{Y}(y)= - f_{X}(g^{-1}(y))\cdot \frac{d}{dy}g^{-1}(y)
\end{equation*}
Since $\left|\frac{d}{dy}g^{-1}(y)\right| = -\frac{d}{dy}g^{-1}(y)$ if $\frac{d}{dy}g^{-1}(y) \le 0$ (which will be the case if $g$ is monotonically decreasing) and $\left|\frac{d}{dy}g^{-1}(y)\right| = \frac{d}{dy}g^{-1}(y)$ if $\frac{d}{dy}g^{-1}(y)\ge 0$ (which will be the case if $g$ is monotonically increasing), then the above two equations can be combined into a single equation:
\begin{equation*}
\therefore f_{Y}(y) = f_{X}(g^{-1}(y))\cdot \left|\frac{d}{dy}g^{-1}(y)\right|  
\end{equation*}
