Skip to content

Tabular, time-series, scientific, and geometric deep learning · Time-series forecasting and representation · SPE018 · Architecture

N-BEATS

N-BEATS forecasts univariate series through stacks of feedforward blocks that explain part of the input history and add forecast components. Generic and interpretable basis variants belong to this one family.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through forecast.nbeats. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

N-BEATS forecasts univariate series through stacks of feedforward blocks that explain part of the input history and add forecast components. Generic and interpretable basis variants belong to this one family.

Question / hypotheses

The operative question is whether the specified representation, symmetry, likelihood or physical constraint improves held-out behavior for this data domain. This is a learning framework, not a null-hypothesis test; losses, attention weights and predictive confidence are not statistical p-values.

Architecture / computational structure

Each MLP block predicts coefficients for a backcast of the input window and a forecast of future values. The backcast is subtracted from the running residual; forecasts accumulate across blocks/stacks.

Assumptions

Trend/seasonal decompositions depend on basis assumptions and are not uniquely causal. Original univariate forecasting design does not automatically handle arbitrary exogenous variables. Regime shifts and long extrapolation beyond learned behavior are challenging.

Formula / computational definition

rl+1=rl−Blθlbr_{l+1}=r_l-B_l\theta_l^b, y^=∑lFlθlf\hat y=\sum_lF_l\theta_l^f, where Bl,FlB_l,F_l are backcast/forecast bases and coefficient vectors come from an MLP. Interpretable variants constrain bases to trend/seasonal forms.

Parameters and notation

Learned or estimated: Block MLP weights and coefficient heads; generic variants may learn basis maps, while interpretable variants use declared fixed bases.

Hyperparameters and effects: Lookback/horizon, block/stacks count, width/depth, basis type, polynomial degree, harmonics, sharing and loss. Richer bases can overfit or destabilize extrapolation.

Fitting, fine-tuning, and adaptation

Fit forecasting loss with rolling-origin splits. Transfer shared blocks or freeze early stacks while adapting forecast heads, then use lower-rate joint fine-tuning if target validation improves. Recheck scaling, frequency and horizon compatibility; changing the horizon changes forecast maps. Preserve source-series checks when retaining a global model.

How to use and calibrate

Define the independent evaluation unit before preprocessing: row/entity, whole set/object, molecule/trajectory, input function or chronological forecasting origin. Keep target construction and normalization within permitted training data. Compare against seasonal-naive and statistical baselines, report scale-aware and horizon-specific errors, and inspect component stability. Avoid random train/test window splits that share overlapping futures.

Example application

Build a strong univariate forecasting baseline with an optional explicit trend/seasonality decomposition. This is a proposed use case, not a claim of validated performance on supplied real data.

Interpretation / pitfalls

Watch out

Assess model error against domain baselines and the stated assumptions. Component-level mathematical correctness does not establish paper reproduction or scientific validity. Use an independent validation design for model selection and a final held-out evaluation for claims; uncertainty and calibration require separate assessment.

Python and R code examples

Scope: One polynomial N-BEATS backcast/forecast basis block with supplied coefficients. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.

Full-model route: Python: official N-BEATS or a verified forecasting library. R: native torch MLP/basis blocks or bridge. The example computes one polynomial backcast/forecast component and residual subtraction.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — One polynomial N-BEATS backcast/forecast basis block with supplied coefficients. Use the shared setup.

Shared setup for this chapter
import numpy as np
def sm(x):
    x=np.asarray(x); e=np.exp(x-x.max(axis=-1,keepdims=True)); return e/e.sum(axis=-1,keepdims=True)
history=np.array([1.,1.2,1.4,1.7]); theta=np.array([1.1,.3,.1])
past=np.linspace(-1,0,4); future=np.array([.25,.5])
B=np.column_stack([np.ones(4),past,past**2]); F=np.column_stack([np.ones(2),future,future**2])
backcast=B@theta; forecast=F@theta; residual=history-backcast
print(backcast,residual,forecast)
R

Component demo, not a trained model — One polynomial N-BEATS backcast/forecast basis block with supplied coefficients. Use the shared setup.

Shared setup for this chapter
sm <- function(x) {
  if(is.null(dim(x))) { e<-exp(x-max(x)); return(e/sum(e)) }
  t(apply(x,1,function(v) { e<-exp(v-max(v)); e/sum(e) }))
}
history<-c(1,1.2,1.4,1.7); theta<-c(1.1,.3,.1)
past<-seq(-1,0,length.out=4); future<-c(.25,.5)
B<-cbind(1,past,past^2); F<-cbind(1,future,future^2)
backcast<-as.vector(B%*%theta); forecast<-F%*%theta; residual<-history-backcast
print(list(backcast=backcast,residual=residual,forecast=forecast))

Sources

From the CodeSplash reference, entry SPE018.