You are on page 1of 2

Seasonal decomposition of time series is a technique used to break down a time series

into its underlying components, such as trend, seasonality, and remainder (residuals).

from statsmodels.tsa.seasonal import seasonal_decompose


result = seasonal_decompose(ts, model='additive', period=365) # Use 'multiplicative' for
multiplicative decomposition
plt.subplot(4, 1, 2)
plt.plot(result.trend, label='Trend')
plt.legend()

plt.subplot(4, 1, 3)
plt.plot(result.seasonal, label='Seasonal')
plt.legend()

plt.subplot(4, 1, 4)
plt.plot(result.resid, label='Residuals')
plt.legend()

Trend

Exponential smoothing is a time series forecasting method that uses a weighted average of past
observations to predict future values. The method gives more weight to recent observations and
gradually decreases the weights as observations become older.

There are different variants of exponential smoothing, including simple exponential smoothing, double
exponential smoothing (Holt's method), and triple exponential smoothing (Holt-Winters method).

from statsmodels.tsa.holtwinters import SimpleExpSmoothing


model = SimpleExpSmoothing(ts)
fit_model = model.fit()

# Forecast future values


forecast = fit_model.forecast(steps=365)
plt.figure(figsize=(12, 6))
plt.plot(ts, label='Original Time Series')
plt.plot(fit_model.fittedvalues, label='Fitted Values', color='green')
plt.plot(forecast, label='Forecast', color='red')
plt.legend()
plt.show()
Autoregressive Integrated Moving Average (ARIMA) models are a class of time series
models that combine autoregression, differencing, and moving average components to make
predictions. The ARIMA model is often denoted as ARIMA(p, d, q), where:

 p: the order of the autoregressive (AR) component

 d: the degree of differencing

 q: the order of the moving average (MA) component

from statsmodels.tsa.arima.model import ARIMA


order = (2, 1, 2) # Example order (p, d, q)
model = ARIMA(ts, order=order)
fit_model = model.fit()

You might also like