Book Image

NumPy Cookbook - Second Edition

By : Ivan Idris
Book Image

NumPy Cookbook - Second Edition

By: Ivan Idris

Overview of this book

<p>NumPy has the ability to give you speed and high productivity. High performance calculations can be done easily with clean and efficient code, and it allows you to execute complex algebraic and mathematical computations in no time.</p> <p>This book will give you a solid foundation in NumPy arrays and universal functions. Starting with the installation and configuration of IPython, you'll learn about advanced indexing and array concepts along with commonly used yet effective functions. You will then cover practical concepts such as image processing, special arrays, and universal functions. You will also learn about plotting with Matplotlib and the related SciPy project with the help of examples. At the end of the book, you will study how to explore atmospheric pressure and its related techniques. By the time you finish this book, you'll be able to write clean and fast code with NumPy.</p>
Table of Contents (19 chapters)
NumPy Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Predicting pressure with an autoregressive model


A very simple predictive model takes the current value of a variable and extrapolates it to the next period. To extrapolate, we can use a simple mathematical function. Since a variety of functions can be approximated by polynomials as in the Taylor series, polynomials of low degree might do the trick. What this boils down to is regression of the previous values to the next values. The corresponding models are therefore called autoregressive.

We have to be careful about overfitting. Cross-validation is a common approach to split the data into train and test sets. We fit the data using the train set and test the fit with the test set. This should reduce bias (see the autoregressive.py file in this book's code bundle):

from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt

 
data = np.load('cbk12.npy')

# Load average pressure
meanp = .1 * data[:,1]

# Split point for test and train data
cutoff = 0.9 * len(meanp...