July 2018
Beginner to intermediate
406 pages
9h 55m
English
Let's now fit a more complex model, a polynomial of degree 2, to see whether it better understands our data:
>>> f2p = np.polyfit(x, y, 2)>>> print(f2p)[ 1.05605675e-02 -5.29774287e+00 1.98466917e+03]>>> f2 = np.poly1d(f2p)>>> print(error(f2, x, y))181347660.764
With plot_web_traffic(x, y, [f1, f2]) we can see how a function of degree 2 manages to model our web traffic data:

The error is 181,347,660.764, which is almost half the error of the straight-line model. This is good, but unfortunately this comes at a price: we now have a more complex function, meaning that we have one more parameter to tune inside polyfit() ...
Read now
Unlock full access