[regression] improved cost function figure
This commit is contained in:
parent
3541f30798
commit
99a8a9d91e
@ -49,16 +49,18 @@ def plot_mse_min(ax, x, y, c):
|
||||
mses = np.zeros(len(ccs))
|
||||
for i, cc in enumerate(ccs):
|
||||
mses[i] = np.mean((y-(cc*x**3.0))**2.0)
|
||||
di = 20
|
||||
i0 = 14
|
||||
imin = np.argmin(mses[i0::di])*di + i0
|
||||
imin = np.argmin(mses)
|
||||
di = 25
|
||||
i0 = 16
|
||||
dimin = np.argmin(mses[i0::di])*di + i0
|
||||
|
||||
ax.plot(c, 500.0, **psB)
|
||||
ax.plot(ccs, mses, **lsAm)
|
||||
ax.plot(ccs[i0::di], mses[i0::di], **psAm)
|
||||
ax.plot(ccs[imin], mses[imin], **psC)
|
||||
ax.plot(ccs[dimin], mses[dimin], **psD)
|
||||
#ax.plot(ccs[imin], mses[imin], **psCm)
|
||||
ax.annotate('Estimated\nminimum of\ncost\nfunction',
|
||||
xy=(ccs[imin], mses[imin]*1.2), xycoords='data',
|
||||
xy=(ccs[dimin], mses[dimin]*1.2), xycoords='data',
|
||||
xytext=(4, 6700), textcoords='data', ha='left',
|
||||
arrowprops=dict(arrowstyle="->", relpos=(0.8,0.0),
|
||||
connectionstyle="angle3,angleA=0,angleB=85") )
|
||||
|
@ -154,6 +154,14 @@ function $f_{cost}(c)$ that maps the parameter value $c$ to a scalar
|
||||
error value. For a given data set we thus can simply plot the cost
|
||||
function as a function of $c$ (\figref{cubiccostfig}).
|
||||
|
||||
\begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise}
|
||||
Then calculate the mean squared error between the data and straight
|
||||
lines for a range of slopes and intercepts using the
|
||||
\varcode{meanSquaredErrorCubic()} function from the previous
|
||||
exercise. Illustrate the error surface using the \code{surface()}
|
||||
function.
|
||||
\end{exercise}
|
||||
|
||||
\begin{figure}[t]
|
||||
\includegraphics{cubiccost}
|
||||
\titlecaption{Minimum of the cost function.}{For a given data set
|
||||
@ -167,14 +175,6 @@ function as a function of $c$ (\figref{cubiccostfig}).
|
||||
the computed range.}\label{cubiccostfig}
|
||||
\end{figure}
|
||||
|
||||
\begin{exercise}{errorSurface.m}{}\label{errorsurfaceexercise}
|
||||
Then calculate the mean squared error between the data and straight
|
||||
lines for a range of slopes and intercepts using the
|
||||
\varcode{meanSquaredErrorCubic()} function from the previous
|
||||
exercise. Illustrate the error surface using the \code{surface()}
|
||||
function.
|
||||
\end{exercise}
|
||||
|
||||
By looking at the plot of the cost function we can visually identify
|
||||
the position of the minimum and thus estimate the optimal value for
|
||||
the parameter $c$. How can we use the error surface to guide an
|
||||
|
Reference in New Issue
Block a user