Which method to use to remove trend from time series?

From what I understand, differencing is necessary to remove the trend and seasonality of a time series. So I assumed it basically does the same thing as signal.detrend from the scipy library.

But I tried differencing and then, separately, used signal.detrend and my time series looked completely different.

Original:

Differencing:

Imported libraries:

The x axis represents months and the y axis is sales. The colours on the first two charts just represent three different years.

Topic difference scipy time-series python

Category Data Science


Detrend does a least squares fit (linear or constant) and subtracts this from your data points. You can look this up in the docs.

Simply taking the difference between consecutive data points will in general lead to other results.

In general the regression based detrending seems to be more reasonable. You could also think about using random sample consensus (RANSAC) to be more robust to outliers.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.