Time-series analysis splits a signal into trend, seasonality and noise — then extends them to forecast what comes next. Tune each component and watch the forecast and its confidence band respond.
The long-run rise or fall — sales growing year on year, temperatures drifting up. Captured by a smooth line through the data.
A pattern that repeats on a fixed cycle — higher every December, busier every weekend. Same shape, again and again.
What's left after removing trend and season — random wobble. Good models leave residuals that look like pure noise.
The cyan line is the observed series. The model fits a trend and a repeating seasonal pattern, then projects them forward as a forecast with a shaded confidence band. Tune the components and horizon, or toggle the trend/season lines on the chart.
Two starting points to understand decomposition and ARIMA forecasting. These open YouTube searches so you can pick the explainer that suits you.
These are YouTube search links (not embeds), so you can choose a current, high-quality explainer for your level.
Load the series, decompose it, check stationarity, fit a model and forecast with intervals.
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.tsa.seasonal import seasonal_decompose
s = pd.read_csv("series.csv", index_col="date", parse_dates=True)["value"]
# Split into trend + seasonal + residual
result = seasonal_decompose(s, model="additive", period=12)
result.plot(); plt.show()
from statsmodels.tsa.stattools import adfuller
def adf(x):
stat, p = adfuller(x)[:2]
print("ADF p-value:", round(p,4),
"-> stationary" if p < 0.05 else "-> non-stationary")
adf(s)
adf(s.diff().dropna()) # difference to remove trend
from statsmodels.tsa.statespace.sarimax import SARIMAX
model = SARIMAX(s, order=(1,1,1),
seasonal_order=(1,1,1,12)).fit()
fc = model.get_forecast(steps=12)
mean = fc.predicted_mean
ci = fc.conf_int() # prediction interval
mean.plot(label="forecast")
plt.fill_between(ci.index, ci.iloc[:,0], ci.iloc[:,1], alpha=.3)
plt.legend(); plt.show()
The time series was decomposed into trend, seasonal and residual parts; stationarity was checked and addressed by differencing; and a SARIMA model produced a forecast with prediction intervals, identifying the patterns and projecting future behaviour — demonstrating CO1.