Smoothing reduces short-term fluctuations in an ordered sequence by replacing each observation with an average of nearby observations. In time-series analysis, the resulting line represents the general trend and provides a more stable reference than individual neighboring points. section 17.2.2
A centered five-point smoother works as follows:
- Average the current value, the two preceding values, and the two following values. section 17.2.2
- Increase the window to obtain a smoother line, recognizing that more averaging also removes more small perturbations. section 17.2.2
- Handle the first and last positions separately because centered windows are incomplete there; extending the nearest defined smoothed value covers the full range. section 17.2.2
Contextual outlier detection
Compare each original observation with the smoothed line rather than only with immediately preceding or following values. This can make a point such as the unusual observation near 120 seconds easier to identify when its absolute value remains normal across the full series. section 17.2.2
Listing 17.3 Creating a smoothed version of time-series data
values = vals1 + vals2 + vals3 + [250] + vals4
smooth_values = []
for v in range(2, len(values)-2):
smooth_values.append(
(values[v-2] + values[v-1] + values[v] + values[v+1] + \
values[v+2])/5)
smooth_values.insert(0, smooth_values[0])
smooth_values.insert(0, smooth_values[0]) #1
smooth_values.extend([smooth_values[-1], smooth_values[-1]])
Shows a concise five-point implementation and the endpoint extension used to produce a full-length smoothed series. section 17.2.2
