01.04.2015 Views

1FfUrl0

1FfUrl0

1FfUrl0

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1<br />

>>> print(res)<br />

[ 3.17389767e+08]<br />

This means that the best straight line fit is the following function:<br />

f(x) = 2.59619213 * x + 989.02487106.<br />

We then use poly1d() to create a model function from the model parameters.<br />

>>> f1 = sp.poly1d(fp1)<br />

>>> print(error(f1, x, y))<br />

317389767.34<br />

We have used full=True to retrieve more details on the fitting process. Normally,<br />

we would not need it, in which case only the model parameters would be returned.<br />

In fact, what we do here is simple curve fitting. You can find out<br />

more about it on Wikipedia by going to http://en.wikipedia.<br />

org/wiki/Curve_fitting.<br />

We can now use f1() to plot our first trained model. In addition to the earlier<br />

plotting instructions, we simply add the following:<br />

fx = sp.linspace(0,x[-1], 1000) # generate X-values for plotting<br />

plt.plot(fx, f1(fx), linewidth=4)<br />

plt.legend(["d=%i" % f1.order], loc="upper left")<br />

The following graph shows our first trained model:<br />

[ 23 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!