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:
Out:
When I replace savgol_filter(oildata, 5, 3) to savgol_filter(oildata, 31, 3):
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

