SARIMAX – Forecasting with External Influences
Until now, all our models depended only on past values of the same time series. That works well when history alone explains the future.
But in the real world, outcomes are rarely isolated. They are influenced by external forces.
This lesson focuses on one powerful idea:
What if we include outside information to improve forecasting?
Real-World Scenario
Imagine forecasting electricity consumption for a city.
Consumption depends on:
- Past electricity usage
- Season (summer vs winter)
- Temperature
If we ignore temperature, forecasts will be inaccurate during heatwaves or cold spells.
This is exactly where SARIMAX shines.
What SARIMAX Adds
SARIMAX is SARIMA with one extra component:
X → eXogenous variables
These are external inputs that influence the target series but are not predicted by it.
Examples of exogenous variables:
- Temperature
- Marketing spend
- Promotions
- Holidays
- Fuel prices
Model Structure
SARIMAX is written as:
SARIMAX(p, d, q)(P, D, Q, m, X)
Everything works like SARIMA, but now the model also learns:
How external variables move the series up or down
Example Data: Electricity Demand + Temperature
We’ll work with a simulated but realistic dataset:
- Electricity demand grows over time
- Seasonal pattern every year
- Higher temperature increases demand
Create the Time Series and External Variable
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(3)
time = np.arange(120)
trend = time * 0.4
seasonal = 20 * np.sin(2 * np.pi * time / 12)
temperature = 25 + 10 * np.sin(2 * np.pi * time / 12)
noise = np.random.normal(0, 4, 120)
demand = trend + seasonal + (temperature * 0.8) + noise
plt.figure(figsize=(9,4))
plt.plot(demand)
plt.title("Electricity Demand Over Time")
plt.show()
This is the actual demand pattern:
What you should notice:
- Upward long-term trend
- Clear seasonal cycles
- Stronger peaks during hotter periods
Visualizing the External Variable
Now look at the temperature pattern itself.
plt.figure(figsize=(9,4))
plt.plot(temperature)
plt.title("Temperature Over Time")
plt.show()
Temperature clearly follows a seasonal cycle. This makes it a strong candidate as an external predictor.
Why SARIMA Alone Is Not Enough
SARIMA can capture:
- Trend
- Seasonality
But it cannot answer:
How much does temperature increase demand?
SARIMAX learns that relationship directly.
How SARIMAX Uses External Information
Internally, the model:
- Fits trend and seasonality
- Adjusts predictions based on temperature values
When temperature rises, forecasts rise. When it falls, forecasts fall.
This makes forecasts more responsive to real conditions.
Conceptual Forecast Comparison
Below is how forecasts behave when external data is included.
Interpretation:
- Without temperature → smooth seasonal curve
- With temperature → peaks adapt to heat changes
Where SARIMAX Is Used
- Energy demand forecasting
- Sales forecasting with promotions
- Traffic prediction with weather
- Supply chain planning
Important Rules
- External variables must be known in advance
- They must logically influence the target
- Garbage external data worsens forecasts
Practice Questions
Q1. Can SARIMAX work without seasonality?
Q2. Why must future exogenous values be known?
Key Takeaways
- SARIMAX extends SARIMA with external signals
- It improves realism and responsiveness
- Perfect for business-driven forecasting
Next, we’ll evaluate models properly using diagnostics and residual analysis.