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$
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$
  • $\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$ – Anya Aug 3 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.