Smoothing functions
Smoothing can help us get rid of noise and outliers in raw data. This, for instance, makes it easier to spot trends in the data. NumPy provides a number of smoothing functions.
Note
These functions can calculate weights in a sliding window as we did in the previous example (for more background information, visit http://en.wikipedia.org/wiki/Window_function).
These functions, except the kaiser
function, require only one parameter—the size of the window, which we will set to 22 for the middle cycle of the sunspot data. The kaiser
function also needs a beta
parameter. With this parameter, the kaiser
function can mimic the other functions.
The NumPy documentation recommends a starting value of 14 for the beta
parameter, so that is what we are going to use too. The code is straightforward and given as follows (the data here is limited to the last 50 years only for easier comparison in the plots):
import numpy as np import sys import matplotlib.pyplot as plt def smooth(weights...