Esc
Ask AIAnswers may be inaccurate; check the linked pages.Esc
Ask anything about these docs, like how to get started or what a function does.

NLinear

chronax.models.nlinear.NLinear · inherits BaseForecaster

Univariate NLinear forecaster (JAX/Flax-NNX port of neuralforecast.NLinear). One linear layer over the input window with last-value normalization: forecast = Linear(y - y_last) + y_last (Zeng et al., 2023). Defaults match neuralforecast 3.1.7 (max_steps=5000, learning_rate=1e-4, identity scaler, MAE loss) so the benchmark harness compares both libraries at native settings.

Maintenance status: Active univariate forecaster. Integrates with the BaseForecaster interface, including conformal prediction intervals via predict(level=...), pickle round-trip, and forecast(fitted=True).

Attributes: * uses_exog: False

__init__(self, h: int, input_size: int = -1, max_steps: int = 5000, learning_rate: Union[float, Callable[[int], float]] = 1e-4, windows_batch_size: int = 1024, loss: Union[str, LossFn] = "mae", scaler: Union[str, Scaler] = "identity", random_seed: int = 1, alias: str = "NLinear")

Initializes the NLinear forecaster parameters.

Parameter Type Default Description
h int - (undocumented)
input_size int -1 If < 1 (default), expands to 3*h.
max_steps int 5000 (undocumented)
learning_rate Union[float, Callable[[int], float]] 1e-4 (undocumented)
windows_batch_size int 1024 (undocumented)
loss Union[str, LossFn] "mae" (undocumented)
scaler Union[str, Scaler] "identity" "identity" (default, matches neuralforecast) or "robust".
random_seed int 1 (undocumented)
alias str "NLinear" (undocumented)

fit(self, y: jnp.ndarray, X: jnp.ndarray | None = None) -> "NLinear"

Fit on a 1-D series.

Parameters:

Parameter Type Default Description
y jnp.ndarray - (undocumented)
X jnp.ndarray \| None None (undocumented)

Returns: Self (the fitted forecaster; sets self.model_). Raises: * NotImplementedError: on exog. * ValueError: if y is not 1-D or shorter than input_size+h. * RuntimeError: on divergence.

predict(self, h: int, X: jnp.ndarray | None = None, level: list[int | float] | None = None) -> dict

Forecast h steps (1 <= h <= self.h). level -> inherited conformal path.

Parameters:

Parameter Type Default Description
h int - (undocumented)
X jnp.ndarray \| None None (undocumented)
level list[int \| float] \| None None (undocumented)

Returns: dict. Keys include {"mean": jnp.ndarray}. If level is provided, includes prediction interval keys (e.g., lower_X, upper_X). Raises: * RuntimeError: If fit(y) has not been called. * ValueError: If h is invalid or level is passed without conformal_params.

forecast(self, y: jnp.ndarray, h: int, X: jnp.ndarray | None = None, X_future: jnp.ndarray | None = None, level: list[int | float] | None = None, fitted: bool = False) -> dict

Stateless fit-then-predict; fitted=True adds one-step-ahead fitted values.

Parameters:

Parameter Type Default Description
y jnp.ndarray - (undocumented)
h int - (undocumented)
X jnp.ndarray \| None None (undocumented)
X_future jnp.ndarray \| None None (undocumented)
level list[int \| float] \| None None (undocumented)
fitted bool False (undocumented)

Returns: dict. Keys include {"mean": jnp.ndarray}. If level is provided, includes prediction interval keys. If fitted=True, includes {"fitted": jnp.ndarray}. Raises: * NotImplementedError: If X or X_future is provided.