Understanding Time-Series Forecasting
Learn the fundamentals of time-series forecasting and how AnoFox Forecast helps you predict the future.
What is a Time Series?
A time series is a sequence of values measured at regular intervals over time.
Real-World Examples
| Domain | Example | Measurement | Frequency |
|---|---|---|---|
| Retail | Daily sales | Units sold | Daily |
| Finance | Stock price | Price | Minutely/Daily |
| Energy | Electricity demand | Megawatts | Hourly |
| Weather | Temperature | Degrees | Hourly |
| Operations | Website traffic | Page views | Hourly/Daily |
| Manufacturing | Production output | Units | Hourly |
Components of a Time Series
Every time series can be decomposed into:
Time Series = Trend + Seasonality + Residual
┌─────────────────────────────────────────────────┐
│ Original Time Series │
│ ╱╲ ╱╲ ╱╲ ╱╲ ╱╲ ╱╲ │
│╱ ╲╱ ╲────╱ ╲╱ ╲────╱ ╲╱ ╲ │
└─────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────┐
│ Trend (long-term direction) │
│ ╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱ │
└─────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────┐
│ Seasonality (repeating patterns) │
│ ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ │
└─────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────┐
│ Residual (random noise) │
│ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ │
└─────────────────────────────────────────────────┘
Understanding Each Component
Trend
Long-term direction or movement. Examples:
- Sales increasing over years
- Stock price rising due to company growth
- Population growing over decades
↗ Uptrend (sales growing)
→ Flat trend (stable demand)
↘ Downtrend (declining interest)
Seasonality
Repeating patterns that occur at fixed intervals. Examples:
- Weekly: Retail sales spike on Fridays/weekends
- Yearly: Holiday shopping spikes in December
- Quarterly: Electricity demand peaks in summer/winter
- Hourly: Website traffic peaks during business hours
Residual (Noise)
Random, unexplained variation. Examples:
- Weather disruptions affecting sales
- Unexpected competitor actions
- Measurement errors
What is Forecasting?
Forecasting is predicting future values based on historical patterns.
The Forecasting Problem
Given historical data:
Past Present Future
├─────────────────────────────────┤ ├──────────────┤
Jan Feb Mar Apr May Jun Jul Aug Sep │ Oct Nov Dec │ Jan Feb Mar
100 110 115 120 125 130 140 155 160 │ ??? ??? ??? │ ??? ??? ???
Goal: Predict what comes next using the patterns you see.
Simple Forecasting Example
Historical data (10 days):
Day: 1 2 3 4 5 6 7 8 9 10
Sales: 100 105 110 115 120 125 130 135 140 145
Pattern: Sales increase by 5 each day
Forecast (next 3 days):
Day: 11 12 13
Sales: 150 155 160
Reality: Sales might be 148, 158, 162 due to factors not captured in the simple trend.
Why Is Forecasting Hard?
Challenge 1: Multiple Patterns
Real data has trends, seasonality, and noise all mixed together:
Sales = Trend + Weekly Pattern + Random Events
120 = 100 + 20 - 5 (price discount)
Challenge 2: Changing Patterns
Patterns shift over time:
Before marketing campaign: Stable demand
After marketing campaign: Demand increases
New trend started
Challenge 3: Limited History
Sometimes you don't have much data:
New product: Only 2 months of sales
But need to forecast 12 months ahead
Challenge 4: Uncertainty
Future cannot be predicted perfectly:
Forecast: 100 units ± 20 (80-120 range)
^
Point estimate (best guess)
How Forecasting Models Work
Step 1: Learn Patterns
The model examines historical data to find patterns:
Input: [100, 105, 110, 115, 120, 125, 130, 135, 140, 145]
Model discovers:
- Trend: +5 per day
- Seasonality: None visible
- Noise: Low
Step 2: Project Forward
The model extends patterns into the future:
Pattern: +5 per day
Last value: 145
Day 11: 145 + 5 = 150
Day 12: 150 + 5 = 155
Day 13: 155 + 5 = 160
Step 3: Add Uncertainty
Models estimate prediction intervals (ranges):
Day 11 forecast: 150
95% prediction interval: 140-160
(95% confident actual value falls in this range)
Types of Forecasting Models
1. Naive Models (Baseline)
Predict the same as yesterday or same as last year.
-- Last value
Forecast = Last Value
Example: Yesterday's sales = 145, so forecast today = 145
-- Seasonal naive
Forecast = Same day last year
Example: Dec 1st last year = 500 units, so forecast this Dec 1st = 500
Pros: Simple, fast, no parameters Cons: Ignores trends, can be inaccurate
2. Statistical Models (Traditional)
Learn mathematical relationships between past and future.
Exponential Smoothing (ETS)
Gives more weight to recent data.
Recent data: ███ (heavy weight)
Old data: ▓ (light weight)
Forecast = Weighted average of history
Best for: Trending data with seasonality Examples: AutoETS, Holt-Winters
ARIMA (AutoRegressive Integrated Moving Average)
Uses past values and errors to predict future.
Forecast = f(Past Values) + f(Past Errors)
Best for: Data with clear trends or seasonal patterns Examples: ARIMA, AutoARIMA
Theta
Simple, effective model that decomposes time series.
Forecast = Trend Line + Seasonal Pattern
Best for: Short-term forecasts, stable data
3. Advanced Models (Complex)
Use sophisticated techniques for complex patterns.
TBATS (Trigonometric seasonality, Box-Cox transformation, ARMA errors, Trend, Seasonal components)
Handles multiple seasonal periods.
Data with:
- Daily seasonality (24 hours)
- Weekly seasonality (7 days)
- Yearly seasonality (365 days)
Model captures all three
Best for: Data with multiple seasonal patterns
MFLES (Median-based Feature-Logic-Expert System)
Combines statistical and feature-based approaches.
Best for: Real-world messy data, outliers, multiple patterns
4. Machine Learning Models (Data-driven)
Learn complex non-linear relationships.
Requires: Feature engineering, more data
Best for: Large datasets with complex patterns
Choosing a Model: Decision Tree
Start: What model should I use?
|
├─ Do I have seasonality? (weekly, yearly patterns)
| |
| ├─ YES → Seasonality is strong?
| | ├─ YES, single seasonality → AutoETS or ETS
| | └─ YES, multiple seasonality → TBATS or MSTL
| |
| └─ NO → Is data trending?
| ├─ YES → AutoARIMA
| └─ NO → Theta or SeasonalNaive
|
└─ Data quality issues? (outliers, gaps)
├─ YES → MFLES (robust to outliers)
└─ NO → AutoETS or AutoARIMA
Key Forecasting Concepts
Forecast Horizon
How far ahead you're predicting.
Forecast horizon = 7 days
Today: Jan 15
Forecast for: Jan 16-22
Longer horizon = More uncertainty
Seasonal Period
How often patterns repeat.
| Data Type | Seasonal Period | Example |
|---|---|---|
| Daily | 7 | Week repeats every 7 days |
| Hourly | 24 | Day repeats every 24 hours |
| Monthly | 12 | Year repeats every 12 months |
Prediction Interval
Range of likely future values.
Point forecast: 100 units
80% interval: 90-110 (likely range)
95% interval: 80-120 (wider range, more conservative)
99% interval: 70-130 (very wide range)
Higher confidence level → Wider interval
Backtesting
Testing model on historical data before deployment.
Training data: Jan-Sep (use to fit model)
Test data: Oct-Dec (use to validate)
Process:
1. Fit model on Jan-Sep
2. Forecast Oct-Dec
3. Compare forecast vs actual Oct-Dec
4. Calculate accuracy metrics
Forecast Accuracy Metrics
How do you know if a forecast is good?
MAE (Mean Absolute Error)
Average difference between forecast and actual.
Forecasts: [100, 102, 98]
Actuals: [105, 100, 99]
Errors: [5, 2, 1]
MAE = (5+2+1)/3 = 2.67
Interpretation: Forecast is off by ~2.67 on average Lower is better
RMSE (Root Mean Squared Error)
Average error, penalizing large errors more.
Emphasizes big mistakes more than MAE
Good for when you want to avoid large errors
Lower is better
MAPE (Mean Absolute Percentage Error)
Percentage error relative to actual values.
MAPE = 3% means forecast is off by 3% on average
Good for comparing across different scales
Lower is better
Common Forecasting Pitfalls
❌ Not Enough Data
Problem: With only 2 weeks of data, hard to detect weekly seasonality Solution: Collect at least 2 full seasonal cycles
❌ Wrong Seasonal Period
Problem: Setting seasonal_period=30 for daily data (should be 7 for weekly) Solution: Test different periods or use seasonality detection
❌ Forecasting Too Far Ahead
Problem: Forecasting 12 months when data is daily/hourly Solution: Keep horizon reasonable (2x the seasonal period maximum)
❌ Trusting Single Forecast
Problem: Using one forecast without checking prediction intervals Solution: Always examine prediction intervals and test multiple models
❌ Ignoring Data Changes
Problem: Using old model after market/business change Solution: Retrain regularly (weekly/monthly) to capture new patterns
Forecasting Workflow
1. Data Collection & Preparation
↓
2. Exploratory Analysis (detect seasonality, trends)
↓
3. Train/Test Split
↓
4. Model Selection & Training
↓
5. Evaluation (MAE, RMSE, MAPE)
↓
6. Model Comparison
↓
7. Choose Best Model
↓
8. Deploy to Production
↓
9. Monitor & Retrain
Quick Reference
| Concept | Definition | Example |
|---|---|---|
| Time Series | Sequential data measured over time | Daily sales, hourly temperature |
| Trend | Long-term direction | Sales increasing 5% per year |
| Seasonality | Repeating patterns | Sales spike in December |
| Forecast Horizon | How far ahead to predict | 30-day forecast |
| Model | Algorithm that learns patterns | ARIMA, ETS, Theta |
| Training | Fitting model to historical data | Use Jan-Sep data |
| Backtesting | Testing on held-out historical data | Use Oct-Dec to test |
| Prediction Interval | Range of likely future values | 90-110 with 95% confidence |
Next Steps
- Seasonality Detection — Detect patterns in your data
- Choosing a Model — Select the right algorithm
- Data Preparation — Clean your data
- Basic Workflow — Run a complete example
Key Takeaways
- ✅ Time series = Data measured over time with patterns
- ✅ Forecasting = Predicting future based on historical patterns
- ✅ Models learn trends and seasonality from past
- ✅ Accuracy measured with MAE, RMSE, MAPE
- ✅ Multiple models available for different situations
- ✅ Always backtest before deployment