How to select window_length and polyorder in scipy.signal.savgol_filter for a daily data

Viewed 250

Say if I would like to smooth the the following daily data named oildata with scipy.signal.savgol_filter:

from scipy.signal import savgol_filter
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

data = np.random.uniform(0, 10, size=90)
index= pd.date_range('20130226', periods=90)
oildata = pd.Series(data, index)

savgol_filter(oildata, 5, 3)
plt.plot(oildata)
plt.plot(pd.Series(savgol_filter(oildata, 5, 3), index=oildata.index))
plt.show()

Out:

enter image description here

Out:

When I replace savgol_filter(oildata, 5, 3) to savgol_filter(oildata, 31, 3):

enter image description here

Beside trial and error methods, I wonder if there are any criteria or methods to select a suitable window_length (which must be a positive odd integer) and polyorder (must be less than window_length) pairs quickly? Thanks.

Reference:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html

0 Answers
Related