2
$\begingroup$

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: enter image description here

Differencing: enter image description here

Imported libraries: enter image description here

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

$\endgroup$

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Thank you very much! When using the regression method, should I divide the original series by the seasonal component and then subtract the original trend from the resulting series? $\endgroup$
    – user66036
    Commented Aug 3, 2019 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.