Advanced Time Series Forecasting with AI: N-BEATS, PatchTST, and Foundation Models
From classical ARIMA to neural and foundation model approaches for production forecasting
Time series forecasting has evolved dramatically. While classical methods like ARIMA and ETS remain reliable for simple patterns, modern deep learning approaches—N-BEATS, PatchTST, and emerging foundation models—now handle complex, multi-scale dependencies with unprecedented accuracy. This guide covers the full spectrum, from model selection and evaluation to backtesting pitfalls.
1. The Forecasting Landscape
2. Classical Foundations (Still Useful)
ARIMA models autocorrelation in differenced series. Use auto.arima (R) or pmdarima (Python) for automatic order selection. Key pitfall: fails with seasonality > 1 year.
ETS (Error-Trend-Seasonal) handles multiplicative seasonality well. Works best on monthly/quarterly data with clear patterns.
Prophet (Facebook) decomposes trend, seasonality, and holidays. Robust to missing data but assumes additive seasonality—can miss complex interactions.
When to use: < 100 time steps, stable patterns, need interpretability.
3. Deep Learning Approaches
#### DeepAR (Amazon)
Probabilistic RNN that outputs distribution parameters. Handles multiple related time series via shared embeddings. Requires careful scaling—use context_length equal to seasonal period.
python
Example using GluonTS
from gluonts.model.deepar import DeepAREstimator
from gluonts.dataset.common import ListDatasetestimator = DeepAREstimator(
prediction_length=24,
context_length=48,
freq="H",
num_layers=3,
cell_type="lstm"
)
predictor = estimator.train(training_data)
Pitfall: Sensitive to context_length—too short misses long-term patterns.
#### N-BEATS (Element AI) Fully connected architecture with backward/forward residual stacks. No feature engineering needed—learns trend and seasonality directly.
python
Using neuralforecast
from neuralforecast.models import NBEATS
from neuralforecast import NeuralForecastmodel = NBEATS(
h=12,
input_size=24,
n_blocks=[3, 3],
mlp_units=[[256, 256], [256, 256]],
n_pool_kernel_size=[2, 2],
pooling_mode="max",
dropout_prob_theta=0.1
)
Key insight: N-BEATS excels on univariate series with strong seasonality. The interpretable variant (N-BEATS-I) decomposes trend/growth/seasonality.
#### N-HiTS (N-BEATS successor) Adds hierarchical interpolation—handles long horizons better than N-BEATS. Uses pooling to reduce temporal resolution at deeper layers.
When to choose: Long forecast horizons (> 100 steps), computational constraints.
#### PatchTST (Google) Breaks time series into "patches" (subsequences) and applies Transformer encoder. Outperforms vanilla Transformers on long sequences.
python
Conceptual structure
Input: [batch, seq_len, channels]
Patch: [batch, num_patches, patch_len, channels]
Transformer encoder processes patches as tokens
Advantage: Captures local patterns (within patches) and global dependencies (between patches). Works well with multivariate data.
#### Temporal Fusion Transformer (TFT) Attention-based model with dedicated encoders for static, known, and observed inputs. Provides quantile outputs for uncertainty.
Best for: Multivariate forecasting with rich covariates (e.g., weather, promotions).
4. Foundation Models (The New Frontier)
These models are pre-trained on massive time series corpora and can forecast without task-specific training.
Example using TimeGPT:
python
from nixtla import NixtlaClientclient = NixtlaClient(api_key="your_key")
forecast = client.forecast(
df=historical_data,
h=24,
freq="H",
time_col="timestamp",
target_col="value"
)
Key considerations:
5. Model Selection Framework
6. Evaluation Metrics
Recommendation: Report MASE + RMSE for robust comparison.
7. Backtesting Best Practices
Expanding window (preferred): Train on [1:t], predict [t+1:t+h], expand training set.
Rolling window: Fixed training size, slide forward. Good for non-stationary data.
Common pitfalls:
python
Proper backtesting with neuralforecast
from neuralforecast.utils import AirPassengers
from neuralforecast.losses.pytorch import MAE
from neuralforecast.models import NBEATSExpanding window cross-validation
from neuralforecast.tsdataset import TimeSeriesDataset
from neuralforecast.crossvalidation import cross_validationcv_results = cross_validation(
model=NBEATS(h=12, input_size=24),
dataset=AirPassengers,
n_windows=3,
step_size=12
)
8. Practical Workflow
9. Common Pitfalls to Avoid
FAQ
Q: When should I use N-BEATS vs PatchTST? A: N-BEATS for univariate series with clear seasonality (faster training). PatchTST for multivariate data or when local patterns matter (e.g., sensor readings with spikes).
Q: Can foundation models replace traditional forecasting? A: Not yet—they excel on common patterns but fail on specialized domains (e.g., medical signals). Use as a strong baseline, not a replacement.
Q: How do I handle multiple frequencies (hourly + daily patterns)? A: Use models with hierarchical decomposition (N-HiTS) or patch-based architectures (PatchTST). Avoid models that assume single frequency.
Q: What's the minimum data size for deep learning? A: At least 1000 time steps for N-BEATS; 5000+ for Transformers. Foundation models can work with < 100 steps but may be unreliable.
Q: How do I choose between MAPE and sMAPE? A: Use sMAPE when data contains zeros (avoids division by zero). Use MAPE for business metrics where percentage error is intuitive.
*Last updated: July 2026. Always verify against each tool's official docs.*
Also available in 中文.