liveBook · Manning

Smoothing

As explained in Outlier Detection in Python

Smoothing is a technique that reduces short-term fluctuations in an ordered sequence by averaging neighboring observations.

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

How Outlier Detection in Python covers it

How deep it goes
Explains a centered five-point average, window-size effects, and endpoint handling, but does not compare smoothing variants.
Examples
Demonstrates a five-point smoothed series and an observation near 120 seconds that is unusual in local context.
What it assumes
Assumes an ordered sequence and teaches the averaging procedure and boundary treatment directly.
What you can do after
Diagnose contextual point outliers by comparing observations with a locally averaged trend line.
How it connects
Connects smoothing to time-series data and contextual point outliers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.