中文
← Back to tutorials

Advanced Time Series Forecasting with AI: N-BEATS, PatchTST, and Foundation Models

From classical ARIMA to neural and foundation model approaches for production forecasting

By AI Skill Navigation Editorial TeamPublished June 26, 2025

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

CategoryExamplesStrengthsWeaknesses

ClassicalARIMA, ETS, ProphetInterpretable, low data needsLinear assumptions, manual tuning Deep LearningDeepAR, N-BEATS, TFTHandles non-linearity, covariatesData-hungry, black-box Foundation ModelsTimeGPT, Chronos, MoiraiZero-shot, cross-domain transferOpaque, high inference cost

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 ListDataset

estimator = 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 NeuralForecast

model = 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.

ModelDeveloperArchitectureKey Feature

TimeGPTNixtlaTransformerZero-shot, API-based ChronosAmazonT5-basedProbabilistic, multiple sizes MoiraiSalesforceTransformerHandles any frequency TimesFMGoogleDecoder-onlyLong context window

Example using TimeGPT:

python
from nixtla import NixtlaClient

client = NixtlaClient(api_key="your_key") forecast = client.forecast( df=historical_data, h=24, freq="H", time_col="timestamp", target_col="value" )

Key considerations:

  • Zero-shot performance: Often matches fine-tuned models on common patterns
  • Domain shift: Fails on highly specialized data (e.g., EEG signals)
  • Cost: API-based models incur per-query fees
  • Reproducibility: Model weights may change without notice
  • 5. Model Selection Framework

  • Data size: < 1000 steps → classical; 1000-100k → deep learning; > 100k → foundation model candidate
  • Pattern complexity: Simple seasonality → N-BEATS; complex interactions → PatchTST/TFT
  • Multivariate need: Yes → TFT or PatchTST; No → N-BEATS/N-HiTS
  • Interpretability: Required → N-BEATS-I or Prophet; Not required → foundation models
  • Deployment constraints: Low latency → N-HiTS; Cloud → foundation models
  • 6. Evaluation Metrics

    MetricFormulaBest ForPitfall

    MAPE(1/n) Σ(y - ŷ)/yScale-independentUndefined for zero values sMAPE(1/n) Σ 2y-ŷ/(y+ŷ)Bounded [0,200]Asymmetric penalty MASEMAE / MAE_naiveComparable across seriesRequires naive baseline RMSE√(1/n) Σ(y-ŷ)²Penalizes large errorsScale-dependent

    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:

  • Look-ahead bias: Using future data for scaling/feature engineering
  • Insufficient history: Need at least 2-3 seasonal cycles for seasonal models
  • Overlapping predictions: When using rolling origin, ensure test windows don't overlap
  • Ignoring frequency changes: Foundation models may mishandle irregularly sampled data
  • python
    

    Proper backtesting with neuralforecast

    from neuralforecast.utils import AirPassengers from neuralforecast.losses.pytorch import MAE from neuralforecast.models import NBEATS

    Expanding window cross-validation

    from neuralforecast.tsdataset import TimeSeriesDataset from neuralforecast.crossvalidation import cross_validation

    cv_results = cross_validation( model=NBEATS(h=12, input_size=24), dataset=AirPassengers, n_windows=3, step_size=12 )

    8. Practical Workflow

  • Exploratory analysis: Check stationarity, seasonality, missing patterns
  • Baseline: Fit naive (last value) and seasonal naive models
  • Classical models: ARIMA/ETS as interpretable benchmarks
  • Deep learning: Start with N-BEATS (fast, robust), then try PatchTST for complex data
  • Foundation models: Test zero-shot on a holdout set before committing
  • Ensemble: Average predictions from 2-3 diverse models often beats any single model
  • 9. Common Pitfalls to Avoid

  • Overfitting to noise: Deep models can memorize random fluctuations—use early stopping
  • Ignoring uncertainty: Always report prediction intervals, not just point forecasts
  • Data leakage: Ensure train/test split respects temporal order
  • Model complexity: Start simple; add complexity only if baseline is beaten
  • API dependency: Foundation models may change behavior without notice—cache results
  • 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 中文.