0
$\begingroup$

I am fairly new to forecasting and I am trying to create a demand forecast for my organization; I am following the methodology outlined here. In step 12 of the process, the author subtracts the trend value from observed value to detrend the data (code shown below):

# Using statmodels: Subtracting the Trend Component.
from statsmodels.tsa.seasonal import seasonal_decompose
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date'], index_col='date')
result_mul = seasonal_decompose(df['value'], model='multiplicative', extrapolate_trend='freq')
detrended = df.value.values - result_mul.trend

My issue is with the last line. If the decomposition is done multiplicatively, why is the trend value be subtracted. Should it not be divided (instead of subtracted)? If Multiplicative Time Series is given by:

Value = Base Level * Trend * Seasonality * Error, has the author made a mistake or is subtraction the only way to detrend the data?

$\endgroup$

1 Answer 1

1
$\begingroup$

Yes the author has made a mistake. The trend needs to be divided from the multiplicative time series while de-trending it. In the next code section he has de-seasonalized correctly:

# Deseasonalize
deseasonalized = df.value.values / result_mul.seasonal
$\endgroup$

Your Answer

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

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