graphtoolbox.models.baseline¶
Reusable non-graph forecasting baselines used by the examples.
- graphtoolbox.models.baseline.rmse(prediction, target) float[source][source]¶
Root mean squared error.
- graphtoolbox.models.baseline.mape(prediction, target, eps: float = 1e-06) float[source][source]¶
Mean absolute percentage error, in percent.
- graphtoolbox.models.baseline.smape(prediction, target, eps: float = 1e-08) float[source][source]¶
Symmetric mean absolute percentage error, in percent.
- graphtoolbox.models.baseline.arimax_forecast(train: DataFrame, test: DataFrame, features: Sequence[str], target: str, slot_col: str, order=(2, 0, 2)) ndarray[source][source]¶
Fit one regression-with-ARMA-errors model per forecast slot.
- class graphtoolbox.models.baseline.CovariateSeq2Seq(n_features: int, hidden_channels: int = 64, horizon: int = 48)[source][source]¶
Bases:
ModuleSmall LSTM encoder-decoder used as a covariate-aware baseline.
- forward(history, future_covariates)[source][source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- graphtoolbox.models.baseline.lstm_forecast(train: DataFrame, test: DataFrame, features: Sequence[str], target: str, step: int = 48, hist_len: int = 336, hidden: int = 64, epochs: int = 40, batch: int = 64, lr: float = 0.001, seed: int = 42, device: str = 'cpu') ndarray[source][source]¶
Train a day-ahead seq2seq LSTM with known future covariates.
- graphtoolbox.models.baseline.chronos2_forecast(full: DataFrame, t0: int, n_test: int, features: Sequence[str], target: str, step: int = 48, ctx: int = 1024, model_id: str = 'amazon/chronos-2', batch_size: int = 64) ndarray[source][source]¶
Run Chronos-2 zero-shot with past and known-future covariates.
- graphtoolbox.models.baseline.xgboost_forecast(train: DataFrame, test: DataFrame, features: Sequence[str], target: str, **model_kwargs) ndarray[source][source]¶
Fit an XGBoost regressor and return its test forecast.
- graphtoolbox.models.baseline.gam_forecast_by_slot(train: DataFrame, test: DataFrame, features: Sequence[str], target: str, slot_col: str, formula, max_iter: int = 1000) ndarray[source][source]¶
Fit one supplied
pygamformula per forecast slot.
- graphtoolbox.models.baseline.chronos_bolt_forecast(series, test_start: int, n_test: int, step: int = 48, context: int = 1024, model_id: str = 'amazon/chronos-bolt-small', batch_size: int = 32) ndarray[source][source]¶
Run a rolling zero-shot Chronos-Bolt forecast.
- graphtoolbox.models.baseline.fit_tabular_baseline(model_type: str, x_train, y_train, x_test, x_validation=None, y_validation=None)[source][source]¶
Fit a tabular baseline used for top-level reconciliation.
Parameters are already scaled by the caller. The return value is
(model, train_prediction, validation_prediction, test_prediction).