# Treating outliers for time series forecasting in Python

What is the best way to treat outliers in a time series forecasting model? In particular, for product demand modeling?

Based on what I've read so far, the following methods can be applied:

1. Winsorization
2. Using dummy variables to remove the effect of explainable spikes (e.g. holiday dummy variables)
3. Identify and replace using R's tsclean

I'm still unsure about the validity of using winsorization to remove spikes in time series, as it may remove valuable information. Number 2 - using dummy variables - only works for spikes that are explainable; however, this cannot be done for spurious outliers, i.e. spikes that occur due to one-off or non-repeatable event.

Number 3 seems to be the best method. Unfortunately, I'm using Python and there doesn't seem to be a Python equivalent for tsclean.

• R also has robets package with outlier-robust exponential smoothing. Calling R from Python is a possibility. – Richard Hardy May 5 '18 at 10:41