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

The Autoregressive Moving Average temperature model


The Autoregressive Moving Average (ARMA) model mixes the Autoregressive (AR) and Moving Average (MA) models. We have already discussed both models. Informally, we can say that we have the autoregressive component with white noise around it. Part of this white noise can be modeled as a linear combination of lag components plus some constant as follows:

  1. Define an autoregressive model with lag 2 using linear coefficients we obtained with a previous script:

    def ar(a):
       ar_p = [1.06517683, -0.08293789]
     
       return ar_p[0] * a[1:-1] + ar_p[1] * a[:-2]
  2. Define the moving average model with lag 1:

    def model(p, ma1):
       c0, c1 = p
     
       return c0 + c1 * ma1
  3. Subtract the autoregressive model values from the data, giving us the error terms (white noise):

    err_terms = temp[cutoff+1:] - ar(temp[cutoff-1:])

    Most of the code for this model should appear familiar to you as shown in the following code:

    import sys
    import numpy as np
    import matplotlib.pyplot as plt...