Time-Series Forecasting (ARIMA & Prophet)
Predict the future from the past. Learn to spot trend and seasonality, make a series stationary, and use ARIMA, SARIMA, and Prophet — without ever shuffling your data.
Learn Time-Series Forecasting (ARIMA & Prophet) in our free AI & Machine Learning course — a beginner-friendly interactive lesson with worked examples, a…
Part of the free AI & Machine Learning course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
A sailor reading the sea separates three things: the slow rise of the tide (the trend), the regular daily ebb and flow (the seasonality ), and the random splash of individual waves (the noise ). Predicting the water level means modelling each part.
Time-series forecasting does exactly this: pull apart trend, seasonality, and noise, model the predictable parts, and project them forward. And just like the sea, you can only learn from the past to predict the future — never the other way around.
Every time series mixes a few components. Trend is the long-term direction. Seasonality is a pattern that repeats over a fixed period (weekly, yearly). Noise is the random leftover.
Classic models assume the series is stationary — its mean and variance stay roughly constant over time. Most real series aren't, so we apply differencing (subtract the previous value) to strip out the trend and bring the series closer to stationary.
Let's pull a tiny series apart. A moving average smooths the seasonal wiggle to reveal the trend, and differencing strips the trend out so the seasonal pattern stands clear. Run it and watch.
ARIMA(p, d, q) is the classic statistical model. p is the autoregressive order (how many past values), d is the differencing order (how many times you difference to reach stationarity), and q is the moving-average order (how many past errors).
Here's ARIMA via statsmodels and a Prophet forecast. Study it (it isn't runnable in the in-browser sandbox) and notice the train/test split is done by time order , never shuffled.
Prophet wants two columns named ds (date) and y (value); ARIMA takes the raw series and an order=(p, d, q) tuple.
The cardinal rule of time series: train on the past, test on the future . Never shuffle. Hold out the most recent slice and evaluate the forecast on it, mimicking real deployment.
Three metrics tell you how good a forecast is:
Fill in the blank so difference() subtracts the previous value at each step. The expected output is in the comments.
Finish the MAE function by dividing the total error by the number of points. The expected output is in the comments.
Split a series by time (no shuffling) and compute RMSE on the held-out period. Only a comment outline is provided.
These are the mistakes that quietly ruin time-series projects. Watch for them.
A random split puts future points in the training set — the future leaks into the past.
Trend or changing variance breaks ARIMA's assumptions and the forecast drifts.
✅ Fix: difference (raise d) to reach stationarity:
A monthly series with a yearly cycle needs seasonal terms, or it forecasts a flat line through the peaks.
✅ Fix: use SARIMA (or Prophet) with a seasonal period:
You can now separate trend and seasonality , make a series stationary with differencing, read ARIMA(p, d, q) , reach for SARIMA or Prophet when needed, and evaluate forecasts with MAE, RMSE, and MAPE — without ever shuffling.
🚀 Up next: Anomaly Detection — finding the rare points that don't fit the pattern.
Practice quiz
What makes time-series data different from ordinary tabular data?
- It has no features
- The order of observations in time matters
- It cannot be forecast
- It is always categorical
Answer: The order of observations in time matters. Time-series observations are ordered in time, so each value depends on the past — order carries information you must respect.
What is the 'trend' component of a time series?
- The long-term upward or downward movement
- A repeating pattern
- Random noise
- A single outlier
Answer: The long-term upward or downward movement. Trend is the slow, long-term direction (rising or falling) once short-term fluctuations are smoothed out.
What is 'seasonality'?
- A long-term trend
- A pattern that repeats over a fixed period (e.g. yearly, weekly)
- Random walk
- Missing data
Answer: A pattern that repeats over a fixed period (e.g. yearly, weekly). Seasonality is a regular, repeating cycle at a fixed period — like higher retail sales every December.
A stationary time series is one whose statistical properties:
- Change wildly over time
- Are always zero
- Stay roughly constant over time (stable mean and variance)
- Depend on the season only
Answer: Stay roughly constant over time (stable mean and variance). Stationarity means the mean, variance, and autocorrelation don't change over time — a key assumption for ARIMA.
In ARIMA(p, d, q), what does the 'd' term represent?
- The number of seasons
- The number of differencing steps to make the series stationary
- The forecast horizon
- The learning rate
Answer: The number of differencing steps to make the series stationary. d is how many times you difference the series (subtract the previous value) to remove trend and reach stationarity.
What do the 'p' and 'q' terms in ARIMA stand for?
- Periods and quarters
- Autoregressive (past values) and moving-average (past errors) orders
- Predictions and queries
- Precision and quality
Answer: Autoregressive (past values) and moving-average (past errors) orders. p is the autoregressive order (how many past values), q is the moving-average order (how many past forecast errors).
What does SARIMA add over plain ARIMA?
- Nothing
- Explicit seasonal terms for repeating cycles
- Faster training only
- Support for images
Answer: Explicit seasonal terms for repeating cycles. SARIMA (Seasonal ARIMA) adds seasonal autoregressive, differencing, and moving-average terms to model periodic patterns.
What is a notable strength of Facebook's Prophet?
- It needs no data
- It handles trend, multiple seasonalities, and holidays with little tuning
- It only works on stationary data
- It ignores trend
Answer: It handles trend, multiple seasonalities, and holidays with little tuning. Prophet is designed to be easy: it decomposes trend, seasonality, and holiday effects and is robust to missing data.
How should you split time-series data into train and test sets?
- Shuffle randomly like normal data
- Keep time order: train on the past, test on the most recent period
- Use only the test set
- Split by feature value
Answer: Keep time order: train on the past, test on the most recent period. Never shuffle a time series — train on earlier data and test on later data, or you leak the future into training.
Which metric expresses forecast error as a percentage of the actual values?
- MAE
- RMSE
- R-squared
- MAPE
Answer: MAPE. MAPE (Mean Absolute Percentage Error) reports error as a percentage, making it easy to interpret across different scales.