Book Image

Learning NumPy Array

By : Ivan Idris
Book Image

Learning NumPy Array

By: Ivan Idris

Overview of this book

Table of Contents (14 chapters)
Learning NumPy Array
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing the day-of-the-year temperature model


Continuing with the work we did in the previous example, I would like to propose a new model, where temperature is a function of the day of the year (between 1 and 366). Of course, this model is not complete, but can be used as a component in a more advanced model, which should take into account the previous autoregressive model that we did with lag 2. The procedure for this model is illustrated as follows:

  1. Fit the temperature data before the cutoff point to a quadratic polynomial just as in the previous section but without averaging:

    poly = np.polyfit(days[:cutoff], temp[:cutoff], 2)
    print poly

    Believe it or not, we get the same polynomial coefficients we got earlier:

    [ -4.91072584e-04   1.92682505e-01  -3.97182941e+00]
    
  2. Calculate the absolute difference between the predicted and actual values:

    delta = np.abs(np.polyval(poly, days[cutoff:]) - temp[cutoff:])
  3. Plot a histogram of the absolute error:

    plt.hist(delta, bins = 10, normed = True)
    plt.show...