Time Series

class endgame.timeseries.BaseForecaster(random_state=None, verbose=False)[source]

Bases: BaseEstimator, RegressorMixin, ABC

Base class for all time series forecasters.

Provides sklearn-compatible interface with time series specific extensions. Designed for integration with signal processing.

Parameters:
  • random_state (int, optional) – Random seed for reproducibility.

  • verbose (bool, default=False) – Enable verbose output.

is_fitted_

Whether the forecaster has been fitted.

Type:

bool

y_

The training time series (stored for forecasting).

Type:

np.ndarray

n_samples_

Number of samples in the training series.

Type:

int

freq_

Inferred or specified frequency of the time series.

Type:

str, optional

Notes

All forecasters follow the pattern: 1. fit(y, X=None) - Learn from historical data 2. predict(horizon) - Generate future predictions 3. update(y_new) - Incrementally update with new data (optional)

For sklearn pipeline compatibility, forecasters also support: - fit_predict(y, horizon) - Fit and predict in one call - score(y_true, y_pred) - Evaluate forecast accuracy

Design Considerations for Signal Processing Integration: - All methods accept raw arrays (no timestamp requirements) - Frequency/sampling rate stored in freq_ attribute - Support for irregularly sampled data via interpolation - Hooks for spectral features (FFT, wavelets) via features parameter

abstractmethod fit(y, X=None, **fit_params)[source]

Fit the forecaster to training data.

Parameters:
  • y (array-like of shape (n_samples,) or (n_samples, n_series)) – Training time series.

  • X (array-like of shape (n_samples, n_features), optional) – Exogenous features aligned with y.

  • **fit_params (dict) – Additional parameters for fitting.

Return type:

BaseForecaster

Returns:

self – Fitted forecaster.

abstractmethod predict(horizon, X=None)[source]

Generate point forecasts.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • X (array-like of shape (horizon, n_features), optional) – Exogenous features for the forecast horizon.

Return type:

ndarray

Returns:

np.ndarray – Point forecasts of shape (horizon,) or (horizon, n_series).

fit_predict(y, horizon, X=None, X_future=None, **fit_params)[source]

Fit and predict in one step.

Parameters:
  • y (array-like) – Training time series.

  • horizon (int) – Forecast horizon.

  • X (array-like, optional) – Historical exogenous features.

  • X_future (array-like, optional) – Future exogenous features for prediction.

  • **fit_params (dict) – Additional fitting parameters.

Return type:

ndarray

Returns:

np.ndarray – Forecasts.

update(y_new, X_new=None)[source]

Update the forecaster with new observations.

Default implementation re-fits with concatenated data. Subclasses may override for incremental updates.

Parameters:
  • y_new (array-like) – New observations to incorporate.

  • X_new (array-like, optional) – Corresponding exogenous features.

Return type:

BaseForecaster

Returns:

self – Updated forecaster.

score(y_true, y_pred=None, horizon=None, metric='mse')[source]

Score the forecaster’s predictions.

Parameters:
  • y_true (array-like) – True values.

  • y_pred (array-like, optional) – Predicted values. If None, generates predictions.

  • horizon (int, optional) – Forecast horizon (required if y_pred is None).

  • metric (str, default="mse") – Scoring metric: “mse”, “rmse”, “mae”, “mape”, “smape”.

Return type:

float

Returns:

float – Negative score (for sklearn compatibility, lower is better).

get_fitted_values()[source]

Get in-sample fitted values (one-step-ahead predictions).

Return type:

ndarray

Returns:

np.ndarray – Fitted values for the training period.

get_residuals()[source]

Get in-sample residuals.

Return type:

ndarray

Returns:

np.ndarray – Residuals (y - fitted_values).

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (BaseForecaster)

Returns:

self (object) – The updated object.

Return type:

BaseForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (BaseForecaster)

Returns:

self (object) – The updated object.

Return type:

BaseForecaster

class endgame.timeseries.ForecasterMixin[source]

Bases: object

Mixin providing common forecaster functionality.

Defines the interface that all forecasters must implement.

abstractmethod predict(horizon, X=None)[source]

Generate point forecasts.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • X (array-like, optional) – Exogenous features for the forecast horizon.

Return type:

ndarray

Returns:

np.ndarray – Point forecasts of shape (horizon,) or (horizon, n_series).

predict_interval(horizon, coverage=0.95, X=None)[source]

Generate prediction intervals.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • coverage (float, default=0.95) – Coverage probability for the interval.

  • X (array-like, optional) – Exogenous features for the forecast horizon.

Return type:

tuple[ndarray, ndarray, ndarray]

Returns:

tuple of np.ndarray – (point_forecast, lower_bound, upper_bound)

predict_quantiles(horizon, quantiles=[0.1, 0.5, 0.9], X=None)[source]

Generate quantile forecasts.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • quantiles (List[float], default=[0.1, 0.5, 0.9]) – Quantile levels to predict.

  • X (array-like, optional) – Exogenous features for the forecast horizon.

Return type:

ndarray

Returns:

np.ndarray – Quantile forecasts of shape (horizon, n_quantiles).

class endgame.timeseries.UnivariateForecasterMixin[source]

Bases: ForecasterMixin

Mixin for univariate time series forecasters.

Forecasters using this mixin expect a single time series as input.

class endgame.timeseries.MultivariateForecasterMixin[source]

Bases: ForecasterMixin

Mixin for multivariate time series forecasters.

Forecasters using this mixin can handle multiple time series or a single series with multiple variables.

class endgame.timeseries.NaiveForecaster(strategy='last', random_state=None, verbose=False)[source]

Bases: BaseForecaster, UnivariateForecasterMixin

Naive forecaster using simple strategies.

Implements several naive forecasting strategies that serve as strong baselines, especially for random walk-like data.

Parameters:
  • strategy (str, default="last") – Forecasting strategy: - “last”: Predict the last observed value (random walk) - “mean”: Predict the mean of the training data - “median”: Predict the median of the training data

  • random_state (int, optional) – Random seed (unused, for API consistency).

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> model = NaiveForecaster(strategy="last")
>>> model.fit(y_train)
>>> forecast = model.predict(horizon=7)

Notes

The “last” strategy is equivalent to a random walk model without drift and often performs surprisingly well on financial and economic data.

fit(y, X=None, **fit_params)[source]

Fit the naive forecaster.

Parameters:
  • y (array-like of shape (n_samples,)) – Training time series.

  • X (ignored) – Exogenous features (not used).

Return type:

NaiveForecaster

Returns:

self – Fitted forecaster.

predict(horizon, X=None)[source]

Generate naive forecasts.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • X (ignored) – Exogenous features (not used).

Return type:

ndarray

Returns:

np.ndarray of shape (horizon,) – Constant forecasts.

predict_interval(horizon, coverage=0.95, X=None)[source]

Generate prediction intervals using residual-based approach.

Parameters:
  • horizon (int) – Forecast horizon.

  • coverage (float, default=0.95) – Coverage probability.

  • X (ignored) – Not used.

Return type:

tuple[ndarray, ndarray, ndarray]

Returns:

tuple – (point_forecast, lower, upper)

get_fitted_values()[source]

Get in-sample fitted values.

For naive forecaster, fitted values are lagged actuals (strategy=last) or constant values (strategy=mean/median).

Return type:

ndarray

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (NaiveForecaster)

Returns:

self (object) – The updated object.

Return type:

NaiveForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (NaiveForecaster)

Returns:

self (object) – The updated object.

Return type:

NaiveForecaster

class endgame.timeseries.SeasonalNaiveForecaster(seasonal_period=1, random_state=None, verbose=False)[source]

Bases: BaseForecaster, UnivariateForecasterMixin

Seasonal naive forecaster.

Predicts using values from the same season in the previous cycle. Essential baseline for data with strong seasonality.

Parameters:
  • seasonal_period (int, default=1) – Length of seasonal cycle (e.g., 7 for weekly, 12 for monthly, 24 for hourly). If None, attempts to auto-detect from data.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> # Weekly seasonality
>>> model = SeasonalNaiveForecaster(seasonal_period=7)
>>> model.fit(daily_sales)
>>> forecast = model.predict(horizon=14)  # Next two weeks
fit(y, X=None, **fit_params)[source]

Fit the seasonal naive forecaster.

Parameters:
  • y (array-like of shape (n_samples,)) – Training time series.

  • X (ignored) – Not used.

Return type:

SeasonalNaiveForecaster

Returns:

self – Fitted forecaster.

predict(horizon, X=None)[source]

Generate seasonal naive forecasts.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • X (ignored) – Not used.

Return type:

ndarray

Returns:

np.ndarray of shape (horizon,) – Seasonal forecasts.

predict_interval(horizon, coverage=0.95, X=None)[source]

Generate prediction intervals.

Return type:

tuple[ndarray, ndarray, ndarray]

Parameters:
get_fitted_values()[source]

Get in-sample fitted values (lag-sp values).

Return type:

ndarray

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (SeasonalNaiveForecaster)

Returns:

self (object) – The updated object.

Return type:

SeasonalNaiveForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (SeasonalNaiveForecaster)

Returns:

self (object) – The updated object.

Return type:

SeasonalNaiveForecaster

class endgame.timeseries.MovingAverageForecaster(window=5, weights=None, center=False, random_state=None, verbose=False)[source]

Bases: BaseForecaster, UnivariateForecasterMixin

Moving average forecaster.

Predicts using simple or weighted moving average of recent observations. Effective for smoothing noise and capturing local trends.

Parameters:
  • window (int, default=5) – Number of recent observations to average.

  • weights (array-like, optional) – Custom weights for each lag. If None, uses equal weights. Weights are applied in reverse order (most recent first).

  • center (bool, default=False) – If True, use centered moving average (for decomposition). Only affects fitted values, not predictions.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> # Simple moving average
>>> model = MovingAverageForecaster(window=7)
>>> model.fit(y_train)
>>> forecast = model.predict(horizon=30)
>>> # Weighted moving average (recent values weighted more)
>>> model = MovingAverageForecaster(window=5, weights=[1, 2, 3, 4, 5])
fit(y, X=None, **fit_params)[source]

Fit the moving average forecaster.

Parameters:
  • y (array-like) – Training time series.

  • X (ignored) – Not used.

Return type:

MovingAverageForecaster

Returns:

self – Fitted forecaster.

predict(horizon, X=None)[source]

Generate moving average forecasts.

Note: For multi-step forecasts, this uses a recursive approach where each forecast becomes input for the next.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • X (ignored) – Not used.

Return type:

ndarray

Returns:

np.ndarray of shape (horizon,) – Forecasts.

predict_interval(horizon, coverage=0.95, X=None)[source]

Generate prediction intervals.

Return type:

tuple[ndarray, ndarray, ndarray]

Parameters:
get_fitted_values()[source]

Get in-sample fitted values.

Return type:

ndarray

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (MovingAverageForecaster)

Returns:

self (object) – The updated object.

Return type:

MovingAverageForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (MovingAverageForecaster)

Returns:

self (object) – The updated object.

Return type:

MovingAverageForecaster

class endgame.timeseries.ExponentialSmoothingForecaster(alpha=0.3, beta=None, optimize=False, initial_method='heuristic', random_state=None, verbose=False)[source]

Bases: BaseForecaster, UnivariateForecasterMixin

Simple exponential smoothing forecaster.

Implements single exponential smoothing (SES) for level forecasting and double exponential smoothing (Holt’s method) for trend.

Parameters:
  • alpha (float, default=0.3) – Smoothing parameter for level (0 < alpha < 1). Higher values give more weight to recent observations.

  • beta (float, optional) – Smoothing parameter for trend (0 < beta < 1). If None, uses simple exponential smoothing without trend.

  • optimize (bool, default=False) – If True, optimize alpha (and beta) using grid search.

  • initial_method (str, default="heuristic") – Method for initializing level (and trend): - “heuristic”: Use first few observations - “estimated”: Estimate from training data

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> # Simple exponential smoothing
>>> model = ExponentialSmoothingForecaster(alpha=0.3)
>>> model.fit(y_train)
>>> forecast = model.predict(horizon=10)
>>> # Holt's linear trend method
>>> model = ExponentialSmoothingForecaster(alpha=0.3, beta=0.1)
>>> # Optimize parameters
>>> model = ExponentialSmoothingForecaster(optimize=True)
fit(y, X=None, **fit_params)[source]

Fit the exponential smoothing forecaster.

Parameters:
  • y (array-like) – Training time series.

  • X (ignored) – Not used.

Return type:

ExponentialSmoothingForecaster

Returns:

self – Fitted forecaster.

predict(horizon, X=None)[source]

Generate exponential smoothing forecasts.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • X (ignored) – Not used.

Return type:

ndarray

Returns:

np.ndarray of shape (horizon,) – Forecasts.

predict_interval(horizon, coverage=0.95, X=None)[source]

Generate prediction intervals.

Return type:

tuple[ndarray, ndarray, ndarray]

Parameters:
get_fitted_values()[source]

Get in-sample fitted values (one-step-ahead forecasts).

Return type:

ndarray

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (ExponentialSmoothingForecaster)

Returns:

self (object) – The updated object.

Return type:

ExponentialSmoothingForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (ExponentialSmoothingForecaster)

Returns:

self (object) – The updated object.

Return type:

ExponentialSmoothingForecaster

class endgame.timeseries.DriftForecaster(random_state=None, verbose=False)[source]

Bases: BaseForecaster, UnivariateForecasterMixin

Drift (random walk with drift) forecaster.

Predicts using the last value plus average historical change. Equivalent to fitting a line between first and last observations.

Parameters:
  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> model = DriftForecaster()
>>> model.fit(y_train)
>>> forecast = model.predict(horizon=10)

Notes

The drift method is equivalent to: y_hat[t+h] = y[t] + h * (y[t] - y[1]) / (t - 1)

This is a useful baseline for trending data where you expect the trend to continue.

fit(y, X=None, **fit_params)[source]

Fit the drift forecaster.

Parameters:
  • y (array-like) – Training time series.

  • X (ignored) – Not used.

Return type:

DriftForecaster

Returns:

self – Fitted forecaster.

predict(horizon, X=None)[source]

Generate drift forecasts.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • X (ignored) – Not used.

Return type:

ndarray

Returns:

np.ndarray of shape (horizon,) – Forecasts.

predict_interval(horizon, coverage=0.95, X=None)[source]

Generate prediction intervals.

Return type:

tuple[ndarray, ndarray, ndarray]

Parameters:
get_fitted_values()[source]

Get in-sample fitted values.

Return type:

ndarray

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (DriftForecaster)

Returns:

self (object) – The updated object.

Return type:

DriftForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (DriftForecaster)

Returns:

self (object) – The updated object.

Return type:

DriftForecaster

class endgame.timeseries.ThetaForecaster(theta=2.0, seasonal_period=None, random_state=None, verbose=False)[source]

Bases: BaseForecaster, UnivariateForecasterMixin

Theta method forecaster.

Implements the Theta method which won the M3 forecasting competition. Decomposes series into two theta lines and combines their forecasts.

Parameters:
  • theta (float, default=2.0) – Theta parameter. theta=0 gives linear regression, theta=2 is the standard Theta method.

  • seasonal_period (int, optional) – If provided, applies seasonal adjustment before forecasting.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> model = ThetaForecaster(theta=2.0)
>>> model.fit(y_train)
>>> forecast = model.predict(horizon=12)

Notes

The Theta method: 1. Decomposes series into theta=0 (linear trend) and theta=2 (amplified curvature) 2. Forecasts theta=0 using linear regression 3. Forecasts theta=2 using simple exponential smoothing 4. Combines forecasts (equal weights)

This simple method often outperforms complex approaches on many datasets.

References

Assimakopoulos, V., & Nikolopoulos, K. (2000). The theta model: a decomposition approach to forecasting. International Journal of Forecasting, 16(4), 521-530.

fit(y, X=None, **fit_params)[source]

Fit the Theta forecaster.

Parameters:
  • y (array-like) – Training time series.

  • X (ignored) – Not used.

Return type:

ThetaForecaster

Returns:

self – Fitted forecaster.

predict(horizon, X=None)[source]

Generate Theta forecasts.

Parameters:
  • horizon (int) – Number of steps ahead to forecast.

  • X (ignored) – Not used.

Return type:

ndarray

Returns:

np.ndarray of shape (horizon,) – Forecasts.

get_fitted_values()[source]

Get in-sample fitted values.

Return type:

ndarray

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (ThetaForecaster)

Returns:

self (object) – The updated object.

Return type:

ThetaForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (ThetaForecaster)

Returns:

self (object) – The updated object.

Return type:

ThetaForecaster

class endgame.timeseries.ExpandingWindowCV(n_splits=5, initial_train_size=None, val_size=None, gap=0, step_size=None)[source]

Bases: BaseCrossValidator

Expanding window cross-validation for time series.

Training window expands with each fold while validation window remains fixed size.

Parameters:
  • n_splits (int, default=5) – Number of folds.

  • initial_train_size (int, optional) – Initial training set size. If None, computed from n_splits.

  • val_size (int, optional) – Validation set size. If None, computed from n_splits.

  • gap (int, default=0) – Number of samples to skip between train and validation.

  • step_size (int, optional) – How many samples to add per fold. If None, uses val_size.

Examples

>>> cv = ExpandingWindowCV(n_splits=5, initial_train_size=100, val_size=20)
>>> for train_idx, val_idx in cv.split(X):
...     # train_idx grows with each fold
...     pass
get_n_splits(X=None, y=None, groups=None)[source]

Return the number of splits.

Return type:

int

Parameters:
  • X (Any | None)

  • y (Any | None)

  • groups (Any | None)

split(X, y=None, groups=None)[source]

Generate train/validation indices.

Parameters:
  • X (array-like) – Input data.

  • y (ignored)

  • groups (ignored)

Yields:

train_idx, val_idx (ndarray) – Training and validation indices for this fold.

Return type:

Generator[tuple[ndarray, ndarray], None, None]

class endgame.timeseries.SlidingWindowCV(n_splits=5, train_size=None, val_size=None, gap=0, step_size=None)[source]

Bases: BaseCrossValidator

Sliding window cross-validation for time series.

Both training and validation windows have fixed sizes and slide through the data.

Parameters:
  • n_splits (int, default=5) – Number of folds.

  • train_size (int, optional) – Training window size.

  • val_size (int, optional) – Validation window size.

  • gap (int, default=0) – Gap between train and validation.

  • step_size (int, optional) – How many samples to slide per fold.

Examples

>>> cv = SlidingWindowCV(n_splits=5, train_size=100, val_size=20)
>>> for train_idx, val_idx in cv.split(X):
...     # Both windows slide forward
...     pass
get_n_splits(X=None, y=None, groups=None)[source]

Return the number of splits.

Return type:

int

Parameters:
  • X (Any | None)

  • y (Any | None)

  • groups (Any | None)

split(X, y=None, groups=None)[source]

Generate train/validation indices.

Return type:

Generator[tuple[ndarray, ndarray], None, None]

Parameters:
class endgame.timeseries.BlockedTimeSeriesSplit(n_splits=5, gap_before=0, gap_after=0)[source]

Bases: BaseCrossValidator

Blocked time series split for reducing temporal leakage.

Splits data into blocks that respect temporal structure and adds gaps to prevent leakage from adjacent periods.

Parameters:
  • n_splits (int, default=5) – Number of folds.

  • gap_before (int, default=0) – Gap samples before validation set.

  • gap_after (int, default=0) – Gap samples after validation set (embargo).

Examples

>>> cv = BlockedTimeSeriesSplit(n_splits=5, gap_before=10, gap_after=5)
>>> for train_idx, val_idx in cv.split(X):
...     pass
get_n_splits(X=None, y=None, groups=None)[source]

Return the number of splits.

Return type:

int

Parameters:
  • X (Any | None)

  • y (Any | None)

  • groups (Any | None)

split(X, y=None, groups=None)[source]

Generate train/validation indices with gaps.

Return type:

Generator[tuple[ndarray, ndarray], None, None]

Parameters:
endgame.timeseries.mase(y_true, y_pred, y_train, seasonal_period=1)[source]

Mean Absolute Scaled Error.

Scales MAE by the in-sample MAE of a naive seasonal forecast. MASE < 1 means the model outperforms seasonal naive.

Parameters:
  • y_true (array-like) – True values.

  • y_pred (array-like) – Predicted values.

  • y_train (array-like) – Training data for computing scaling factor.

  • seasonal_period (int, default=1) – Seasonal period for naive forecast (1 = random walk).

Return type:

float

Returns:

float – MASE score.

endgame.timeseries.smape(y_true, y_pred)[source]

Symmetric Mean Absolute Percentage Error.

Parameters:
  • y_true (array-like) – True values.

  • y_pred (array-like) – Predicted values.

Return type:

float

Returns:

float – SMAPE in percentage (0-200%).

endgame.timeseries.mape(y_true, y_pred)[source]

Mean Absolute Percentage Error.

Parameters:
  • y_true (array-like) – True values.

  • y_pred (array-like) – Predicted values.

Return type:

float

Returns:

float – MAPE in percentage.

endgame.timeseries.rmsse(y_true, y_pred, y_train)[source]

Root Mean Squared Scaled Error.

Used in M5 forecasting competition.

Parameters:
  • y_true (array-like) – True values.

  • y_pred (array-like) – Predicted values.

  • y_train (array-like) – Training data for scaling.

Return type:

float

Returns:

float – RMSSE score.

endgame.timeseries.wape(y_true, y_pred)[source]

Weighted Absolute Percentage Error.

Parameters:
  • y_true (array-like) – True values.

  • y_pred (array-like) – Predicted values.

Return type:

float

Returns:

float – WAPE in percentage.

endgame.timeseries.coverage(y_true, lower, upper)[source]

Compute prediction interval coverage.

Parameters:
  • y_true (array-like) – True values.

  • lower (array-like) – Lower bounds of prediction intervals.

  • upper (array-like) – Upper bounds of prediction intervals.

Return type:

float

Returns:

float – Coverage probability (0-1).

endgame.timeseries.interval_width(lower, upper)[source]

Compute average prediction interval width.

Parameters:
  • lower (array-like) – Lower bounds.

  • upper (array-like) – Upper bounds.

Return type:

float

Returns:

float – Mean interval width.

endgame.timeseries.winkler_score(y_true, lower, upper, alpha=0.05)[source]

Compute Winkler score for prediction intervals.

Combines coverage and sharpness. Lower is better.

Parameters:
  • y_true (array-like) – True values.

  • lower (array-like) – Lower bounds.

  • upper (array-like) – Upper bounds.

  • alpha (float, default=0.05) – Significance level (1 - coverage).

Return type:

float

Returns:

float – Winkler score.

class endgame.timeseries.AutoARIMAForecaster(d=None, D=None, max_p=5, max_q=5, max_P=2, max_Q=2, seasonal=True, m=1, stationary=False, ic='aicc', approximation=True, random_state=None, verbose=False)[source]

Bases: StatsForecastWrapper

AutoARIMA forecaster via statsforecast.

Automatically selects the best ARIMA model using AIC/BIC. 20x faster than pmdarima.

Parameters:
  • d (int, optional) – Order of differencing. If None, auto-selected.

  • D (int, optional) – Order of seasonal differencing. If None, auto-selected.

  • max_p (int, default=5) – Maximum p (AR order).

  • max_q (int, default=5) – Maximum q (MA order).

  • max_P (int, default=2) – Maximum seasonal P.

  • max_Q (int, default=2) – Maximum seasonal Q.

  • seasonal (bool, default=True) – Whether to fit seasonal ARIMA.

  • m (int, default=1) – Seasonal period.

  • stationary (bool, default=False) – If True, restricts search to stationary models.

  • ic (str, default="aicc") – Information criterion: “aicc”, “aic”, “bic”.

  • approximation (bool, default=True) – Use approximation for speed.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> # Monthly data with yearly seasonality
>>> model = AutoARIMAForecaster(seasonal=True, m=12)
>>> model.fit(monthly_sales)
>>> forecast = model.predict(horizon=12)
>>> # Non-seasonal ARIMA
>>> model = AutoARIMAForecaster(seasonal=False)
>>> model.fit(daily_returns)
set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (AutoARIMAForecaster)

Returns:

self (object) – The updated object.

Return type:

AutoARIMAForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (AutoARIMAForecaster)

Returns:

self (object) – The updated object.

Return type:

AutoARIMAForecaster

class endgame.timeseries.AutoETSForecaster(model='ZZZ', season_length=1, damped=None, random_state=None, verbose=False)[source]

Bases: StatsForecastWrapper

AutoETS (Error, Trend, Seasonal) forecaster via statsforecast.

Automatically selects the best exponential smoothing model.

Parameters:
  • model (str, default="ZZZ") –

    ETS model specification (Error, Trend, Seasonal): - Error: A(dditive), M(ultiplicative), Z(auto) - Trend: N(one), A(dditive), Ad(damped additive), M(ultiplicative), Md(damped multiplicative), Z(auto) - Seasonal: N(one), A(dditive), M(ultiplicative), Z(auto) Examples: “AAN” (additive error, additive trend, no seasonal),

    ”ZZZ” (auto-select all)

  • season_length (int, default=1) – Seasonal period.

  • damped (bool, optional) – Whether to use damped trend. If None, auto-selected.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> # Auto-select ETS model
>>> model = AutoETSForecaster(model="ZZZ", season_length=12)
>>> model.fit(monthly_sales)
>>> forecast = model.predict(horizon=12)
>>> # Specific model: additive error, damped trend, multiplicative seasonal
>>> model = AutoETSForecaster(model="AdM", season_length=12)
set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (AutoETSForecaster)

Returns:

self (object) – The updated object.

Return type:

AutoETSForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (AutoETSForecaster)

Returns:

self (object) – The updated object.

Return type:

AutoETSForecaster

class endgame.timeseries.AutoThetaForecaster(season_length=1, decomposition_type='multiplicative', random_state=None, verbose=False)[source]

Bases: StatsForecastWrapper

AutoTheta forecaster via statsforecast.

Implements optimized Theta method with automatic selection.

Parameters:
  • season_length (int, default=1) – Seasonal period.

  • decomposition_type (str, default="multiplicative") – Type of seasonal decomposition: “multiplicative” or “additive”.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> model = AutoThetaForecaster(season_length=12)
>>> model.fit(monthly_data)
>>> forecast = model.predict(horizon=6)
set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (AutoThetaForecaster)

Returns:

self (object) – The updated object.

Return type:

AutoThetaForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (AutoThetaForecaster)

Returns:

self (object) – The updated object.

Return type:

AutoThetaForecaster

class endgame.timeseries.MSTLForecaster(season_lengths=[7], trend_forecaster='auto_arima', stl_kwargs=None, random_state=None, verbose=False)[source]

Bases: BaseForecaster, UnivariateForecasterMixin

MSTL (Multiple Seasonal-Trend decomposition using Loess) forecaster.

Handles multiple seasonal patterns (e.g., daily + weekly + yearly). Decomposes series then forecasts trend and seasonal components separately.

Parameters:
  • season_lengths (List[int], default=[7]) – List of seasonal periods to model.

  • trend_forecaster (str, default="auto_arima") – Method for forecasting trend: “auto_arima”, “auto_ets”, “naive”.

  • stl_kwargs (dict, optional) – Additional arguments for STL decomposition.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> # Hourly data with daily and weekly seasonality
>>> model = MSTLForecaster(season_lengths=[24, 168])
>>> model.fit(hourly_demand)
>>> forecast = model.predict(horizon=48)
fit(y, X=None, **fit_params)[source]

Fit MSTL model.

Return type:

MSTLForecaster

Parameters:
predict(horizon, X=None)[source]

Generate MSTL forecasts.

Return type:

ndarray

Parameters:
  • horizon (int)

  • X (Any | None)

get_fitted_values()[source]

Get in-sample fitted values.

Return type:

ndarray

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (MSTLForecaster)

Returns:

self (object) – The updated object.

Return type:

MSTLForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (MSTLForecaster)

Returns:

self (object) – The updated object.

Return type:

MSTLForecaster

class endgame.timeseries.CESForecaster(season_length=1, model='Z', random_state=None, verbose=False)[source]

Bases: StatsForecastWrapper

Complex Exponential Smoothing forecaster via statsforecast.

Uses complex-valued exponential smoothing for improved accuracy on some data patterns.

Parameters:
  • season_length (int, default=1) – Seasonal period.

  • model (str, default="Z") – Model type: “N” (none), “S” (simple), “P” (partial), “F” (full), “Z” (auto).

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (CESForecaster)

Returns:

self (object) – The updated object.

Return type:

CESForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (CESForecaster)

Returns:

self (object) – The updated object.

Return type:

CESForecaster

class endgame.timeseries.TSFreshFeatureExtractor(preset='efficient', column_id='id', column_sort=None, column_value=None, select_relevant=True, fdr_level=0.05, n_jobs=-1, show_warnings=False)[source]

Bases: BaseEstimator, TransformerMixin

Sklearn-compatible tsfresh feature extractor.

Wraps tsfresh’s feature extraction with automatic relevance filtering and imputation.

Parameters:
  • preset (str, default="efficient") – Feature calculation preset: - “minimal”: ~10 features per column (fast) - “efficient”: ~100 features per column (balanced) - “comprehensive”: ~800 features per column (slow but thorough)

  • column_id (str, default="id") – Name of the column containing series identifiers.

  • column_sort (str, optional) – Name of the column to sort by (e.g., timestamp).

  • column_value (str, optional) – Name of the column containing values (if single-column series).

  • select_relevant (bool, default=True) – Whether to filter features by relevance to target.

  • fdr_level (float, default=0.05) – False discovery rate for feature selection.

  • n_jobs (int, default=-1) – Number of parallel jobs (-1 for all cores).

  • show_warnings (bool, default=False) – Whether to show tsfresh warnings.

selected_features_

Names of selected features after fitting.

Type:

List[str]

feature_settings_

Feature calculation settings used.

Type:

dict

Examples

>>> # Basic usage
>>> extractor = TSFreshFeatureExtractor(preset="efficient")
>>> features = extractor.fit_transform(df, y=target)
>>> # Without relevance filtering
>>> extractor = TSFreshFeatureExtractor(select_relevant=False)
>>> features = extractor.transform(df)
fit(X, y=None, **fit_params)[source]

Fit the feature extractor.

Parameters:
  • X (DataFrame) – Input data with columns for id, sort, and values.

  • y (array-like, optional) – Target variable for relevance filtering. Required if select_relevant=True.

Return type:

TSFreshFeatureExtractor

Returns:

self – Fitted extractor.

transform(X)[source]

Transform time series to features.

Parameters:

X (DataFrame) – Input data.

Return type:

ndarray

Returns:

np.ndarray – Extracted features.

fit_transform(X, y=None, **fit_params)[source]

Fit and transform in one step.

Return type:

ndarray

get_feature_names_out(input_features=None)[source]

Get output feature names.

Return type:

list[Text]

class endgame.timeseries.TimeSeriesFeatureExtractor(features=None, window_sizes=[7, 14, 30], lag_range=(1, 10))[source]

Bases: BaseEstimator, TransformerMixin

Fast time series feature extractor without tsfresh dependency.

Extracts common time series features that are useful for GBDT models. Faster than tsfresh but with fewer features.

Parameters:
  • features (List[str], optional) –

    Features to extract. If None, extracts all. Options: “statistics”, “trend”, “seasonality”, “autocorr”, “entropy”,

    ”spectral”, “peaks”, “crossings”.

  • window_sizes (List[int], default=[7, 14, 30]) – Window sizes for rolling features.

  • lag_range (tuple, default=(1, 10)) – Range of lags for autocorrelation features.

Examples

>>> extractor = TimeSeriesFeatureExtractor(features=["statistics", "trend"])
>>> features = extractor.fit_transform(time_series_array)
fit(X, y=None, **fit_params)[source]

Fit the extractor (learn feature names).

Parameters:

X (array-like of shape (n_samples,) or (n_samples, n_series)) – Time series data.

Return type:

TimeSeriesFeatureExtractor

Returns:

self – Fitted extractor.

transform(X)[source]

Extract features from time series.

Parameters:

X (array-like of shape (n_samples,) or (n_series, n_samples)) – Time series data. If 2D, each row is a separate series.

Return type:

ndarray

Returns:

np.ndarray – Extracted features of shape (n_series, n_features).

fit_transform(X, y=None, **fit_params)[source]

Fit and transform in one step.

Return type:

ndarray

get_feature_names_out(input_features=None)[source]

Get output feature names.

Return type:

list[Text]

class endgame.timeseries.NBEATSForecaster(input_chunk_length=30, output_chunk_length=7, num_stacks=30, num_blocks=1, num_layers=4, layer_widths=256, expansion_coefficient_dim=5, generic_architecture=True, batch_size=32, n_epochs=100, learning_rate=0.001, random_state=None, verbose=False)[source]

Bases: DartsForecasterWrapper

N-BEATS (Neural Basis Expansion Analysis) forecaster.

State-of-the-art neural architecture for time series forecasting based on backward and forward residual links.

Parameters:
  • input_chunk_length (int, default=30) – Lookback window length.

  • output_chunk_length (int, default=7) – Forecast horizon for training.

  • num_stacks (int, default=30) – Number of stacks.

  • num_blocks (int, default=1) – Number of blocks per stack.

  • num_layers (int, default=4) – Number of fully connected layers per block.

  • layer_widths (int, default=256) – Width of fully connected layers.

  • expansion_coefficient_dim (int, default=5) – Dimension of expansion coefficients.

  • generic_architecture (bool, default=True) – Whether to use generic architecture (vs interpretable).

  • batch_size (int, default=32) – Training batch size.

  • n_epochs (int, default=100) – Number of training epochs.

  • learning_rate (float, default=1e-3) – Learning rate.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

Examples

>>> model = NBEATSForecaster(input_chunk_length=30, output_chunk_length=7)
>>> model.fit(train_data)
>>> forecast = model.predict(horizon=7)

References

Oreshkin et al. (2020). “N-BEATS: Neural basis expansion analysis for interpretable time series forecasting.”

set_fit_request(*, val_y='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • val_y (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for val_y parameter in fit.

  • self (NBEATSForecaster)

Returns:

self (object) – The updated object.

Return type:

NBEATSForecaster

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (NBEATSForecaster)

Returns:

self (object) – The updated object.

Return type:

NBEATSForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (NBEATSForecaster)

Returns:

self (object) – The updated object.

Return type:

NBEATSForecaster

class endgame.timeseries.NHITSForecaster(input_chunk_length=30, output_chunk_length=7, num_stacks=3, num_blocks=1, num_layers=2, layer_widths=512, batch_size=32, n_epochs=100, learning_rate=0.001, random_state=None, verbose=False)[source]

Bases: DartsForecasterWrapper

N-HiTS (Neural Hierarchical Interpolation) forecaster.

Improved version of N-BEATS with hierarchical interpolation for better long-horizon forecasting.

Parameters:
  • input_chunk_length (int, default=30) – Lookback window length.

  • output_chunk_length (int, default=7) – Forecast horizon for training.

  • num_stacks (int, default=3) – Number of stacks.

  • num_blocks (int, default=1) – Number of blocks per stack.

  • num_layers (int, default=2) – Number of FC layers per block.

  • layer_widths (int, default=512) – Width of FC layers.

  • batch_size (int, default=32) – Training batch size.

  • n_epochs (int, default=100) – Number of training epochs.

  • learning_rate (float, default=1e-3) – Learning rate.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

References

Challu et al. (2022). “N-HiTS: Neural Hierarchical Interpolation for Time Series Forecasting.”

set_fit_request(*, val_y='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • val_y (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for val_y parameter in fit.

  • self (NHITSForecaster)

Returns:

self (object) – The updated object.

Return type:

NHITSForecaster

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (NHITSForecaster)

Returns:

self (object) – The updated object.

Return type:

NHITSForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (NHITSForecaster)

Returns:

self (object) – The updated object.

Return type:

NHITSForecaster

class endgame.timeseries.TFTForecaster(input_chunk_length=30, output_chunk_length=7, hidden_size=64, lstm_layers=1, num_attention_heads=4, hidden_continuous_size=8, dropout=0.1, batch_size=32, n_epochs=100, learning_rate=0.001, add_relative_index=True, random_state=None, verbose=False)[source]

Bases: DartsForecasterWrapper

Temporal Fusion Transformer forecaster.

Multi-horizon forecasting with interpretable attention mechanism. Handles static, known future, and observed inputs.

Parameters:
  • input_chunk_length (int, default=30) – Lookback window length.

  • output_chunk_length (int, default=7) – Forecast horizon.

  • hidden_size (int, default=64) – Hidden state size.

  • lstm_layers (int, default=1) – Number of LSTM layers.

  • num_attention_heads (int, default=4) – Number of attention heads.

  • hidden_continuous_size (int, default=8) – Hidden size for continuous variable processing.

  • dropout (float, default=0.1) – Dropout rate.

  • batch_size (int, default=32) – Training batch size.

  • n_epochs (int, default=100) – Number of training epochs.

  • learning_rate (float, default=1e-3) – Learning rate.

  • add_relative_index (bool, default=True) – Whether to add relative time index as feature.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

References

Lim et al. (2021). “Temporal Fusion Transformers for Interpretable Multi-horizon Time Series Forecasting.”

set_fit_request(*, val_y='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • val_y (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for val_y parameter in fit.

  • self (TFTForecaster)

Returns:

self (object) – The updated object.

Return type:

TFTForecaster

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (TFTForecaster)

Returns:

self (object) – The updated object.

Return type:

TFTForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (TFTForecaster)

Returns:

self (object) – The updated object.

Return type:

TFTForecaster

class endgame.timeseries.PatchTSTForecaster(input_chunk_length=32, output_chunk_length=7, patch_length=16, d_model=128, nhead=4, num_encoder_layers=3, dim_feedforward=256, dropout=0.1, batch_size=32, n_epochs=100, learning_rate=0.001, random_state=None, verbose=False)[source]

Bases: DartsForecasterWrapper

Patch Time Series Transformer forecaster.

Transformer model that uses patching for efficient long sequence modeling.

Parameters:
  • input_chunk_length (int, default=32) – Lookback window length (should be divisible by patch_length).

  • output_chunk_length (int, default=7) – Forecast horizon.

  • patch_length (int, default=16) – Length of each patch.

  • d_model (int, default=128) – Dimension of the model.

  • nhead (int, default=4) – Number of attention heads.

  • num_encoder_layers (int, default=3) – Number of encoder layers.

  • dim_feedforward (int, default=256) – Feedforward network dimension.

  • dropout (float, default=0.1) – Dropout rate.

  • batch_size (int, default=32) – Training batch size.

  • n_epochs (int, default=100) – Number of training epochs.

  • learning_rate (float, default=1e-3) – Learning rate.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

References

Nie et al. (2023). “A Time Series is Worth 64 Words: Long-term Forecasting with Transformers.”

set_fit_request(*, val_y='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • val_y (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for val_y parameter in fit.

  • self (PatchTSTForecaster)

Returns:

self (object) – The updated object.

Return type:

PatchTSTForecaster

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (PatchTSTForecaster)

Returns:

self (object) – The updated object.

Return type:

PatchTSTForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (PatchTSTForecaster)

Returns:

self (object) – The updated object.

Return type:

PatchTSTForecaster

class endgame.timeseries.DLinearForecaster(input_chunk_length=30, output_chunk_length=7, shared_weights=False, kernel_size=25, batch_size=32, n_epochs=100, learning_rate=0.001, random_state=None, verbose=False)[source]

Bases: DartsForecasterWrapper

DLinear forecaster.

Simple linear model with trend-seasonal decomposition. Often competitive with complex transformers while being much faster.

Parameters:
  • input_chunk_length (int, default=30) – Lookback window length.

  • output_chunk_length (int, default=7) – Forecast horizon.

  • shared_weights (bool, default=False) – Whether to share weights across series.

  • kernel_size (int, default=25) – Kernel size for moving average decomposition.

  • batch_size (int, default=32) – Training batch size.

  • n_epochs (int, default=100) – Number of training epochs.

  • learning_rate (float, default=1e-3) – Learning rate.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

References

Zeng et al. (2023). “Are Transformers Effective for Time Series Forecasting?”

set_fit_request(*, val_y='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • val_y (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for val_y parameter in fit.

  • self (DLinearForecaster)

Returns:

self (object) – The updated object.

Return type:

DLinearForecaster

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (DLinearForecaster)

Returns:

self (object) – The updated object.

Return type:

DLinearForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (DLinearForecaster)

Returns:

self (object) – The updated object.

Return type:

DLinearForecaster

class endgame.timeseries.TimesNetForecaster(input_chunk_length=30, output_chunk_length=7, hidden_size=64, num_encoder_layers=2, num_kernels=6, batch_size=32, n_epochs=100, learning_rate=0.001, random_state=None, verbose=False)[source]

Bases: DartsForecasterWrapper

TimesNet forecaster.

Temporal 2D-variation modeling for time series analysis. Converts 1D time series to 2D tensors for pattern extraction.

Parameters:
  • input_chunk_length (int, default=30) – Lookback window length.

  • output_chunk_length (int, default=7) – Forecast horizon.

  • hidden_size (int, default=64) – Hidden dimension size.

  • num_encoder_layers (int, default=2) – Number of encoder layers.

  • num_kernels (int, default=6) – Number of inception kernels.

  • batch_size (int, default=32) – Training batch size.

  • n_epochs (int, default=100) – Number of training epochs.

  • learning_rate (float, default=1e-3) – Learning rate.

  • random_state (int, optional) – Random seed.

  • verbose (bool, default=False) – Enable verbose output.

References

Wu et al. (2023). “TimesNet: Temporal 2D-Variation Modeling for General Time Series Analysis.”

set_fit_request(*, val_y='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • val_y (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for val_y parameter in fit.

  • self (TimesNetForecaster)

Returns:

self (object) – The updated object.

Return type:

TimesNetForecaster

set_predict_request(*, horizon='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in predict.

  • self (TimesNetForecaster)

Returns:

self (object) – The updated object.

Return type:

TimesNetForecaster

set_score_request(*, horizon='$UNCHANGED$', metric='$UNCHANGED$', y_pred='$UNCHANGED$', y_true='$UNCHANGED$')

Configure whether metadata should be requested to be passed to the score method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:
  • horizon (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for horizon parameter in score.

  • metric (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for metric parameter in score.

  • y_pred (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_pred parameter in score.

  • y_true (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for y_true parameter in score.

  • self (TimesNetForecaster)

Returns:

self (object) – The updated object.

Return type:

TimesNetForecaster

class endgame.timeseries.RocketTransformer(n_kernels=10000, normalize=True, random_state=None)[source]

Bases: BaseEstimator, TransformerMixin

ROCKET (Random Convolutional Kernel Transform) for time series.

Transforms time series using random convolutional kernels with random length, weights, bias, dilation, and padding. Extracts max value and proportion of positive values (PPV) from each convolution.

Parameters:
  • n_kernels (int, default=10000) – Number of random kernels to generate.

  • normalize (bool, default=True) – Whether to normalize input time series.

  • random_state (int, optional) – Random seed for reproducibility.

n_features_out_

Number of output features (2 * n_kernels).

Type:

int

Examples

>>> transformer = RocketTransformer(n_kernels=10000)
>>> X_transformed = transformer.fit_transform(X_train)
>>> print(X_transformed.shape)  # (n_samples, 20000)

Notes

ROCKET generates 2 features per kernel: - Maximum value of the convolution - Proportion of positive values (PPV)

For 10,000 kernels (default), this produces 20,000 features.

fit(X, y=None)[source]

Fit the ROCKET transformer.

Parameters:
  • X (array-like of shape (n_samples, n_timepoints) or (n_samples, n_channels, n_timepoints)) – Training time series.

  • y (ignored)

Returns:

self

transform(X)[source]

Transform time series using ROCKET kernels.

Parameters:

X (array-like of shape (n_samples, n_timepoints) or (n_samples, n_channels, n_timepoints)) – Time series to transform.

Return type:

ndarray

Returns:

np.ndarray of shape (n_samples, n_features) – Transformed features.

class endgame.timeseries.MiniRocketTransformer(n_kernels=10000, random_state=None)[source]

Bases: BaseEstimator, TransformerMixin

MiniROCKET transform for time series.

A faster, almost deterministic variant of ROCKET using fixed kernels with limited weight values. Up to 75x faster than ROCKET on large datasets.

Parameters:
  • n_kernels (int, default=10000) – Number of kernels (approximately - actual number depends on implementation).

  • random_state (int, optional) – Random seed for reproducibility.

n_features_out_

Number of output features.

Type:

int

Examples

>>> transformer = MiniRocketTransformer()
>>> X_transformed = transformer.fit_transform(X_train)

Notes

Key differences from ROCKET: - Uses fixed kernels of length 9 - Weights restricted to two values (-1 and 2) - Uses 84 fixed convolutions as seeds for dilations - Does NOT require normalized input - Almost deterministic (small random component in dilation selection)

Minimum time series length is 9.

fit(X, y=None)[source]

Fit the MiniROCKET transformer.

Parameters:
  • X (array-like of shape (n_samples, n_timepoints)) – Training time series. Must have length >= 9.

  • y (ignored)

Returns:

self

transform(X)[source]

Transform time series using MiniROCKET.

Parameters:

X (array-like) – Time series to transform.

Return type:

ndarray

Returns:

np.ndarray of shape (n_samples, n_features) – Transformed features.

class endgame.timeseries.MultiRocketTransformer(n_kernels=10000, n_features_per_kernel=4, random_state=None)[source]

Bases: BaseEstimator, TransformerMixin

MultiROCKET transform for time series.

Extension of MiniROCKET for multivariate time series with additional pooling operations (mean, standard deviation).

Parameters:
  • n_kernels (int, default=10000) – Number of kernels.

  • n_features_per_kernel (int, default=4) – Number of features per kernel (PPV + additional pooling).

  • random_state (int, optional) – Random seed.

Examples

>>> transformer = MultiRocketTransformer()
>>> X_transformed = transformer.fit_transform(X_train)  # Multivariate OK
fit(X, y=None)[source]

Fit MultiROCKET transformer.

transform(X)[source]

Transform time series using MultiROCKET.

Return type:

ndarray

class endgame.timeseries.HydraTransformer(n_kernels=8, n_groups=64, random_state=None)[source]

Bases: BaseEstimator, TransformerMixin

HYDRA (Hybrid Dictionary-ROCKET) transform for time series.

Combines dictionary methods with convolutional kernels. Uses competing kernels that extract and count symbolic patterns while leveraging kernel transformations.

Parameters:
  • n_kernels (int, default=8) – Number of kernels per group.

  • n_groups (int, default=64) – Number of kernel groups.

  • random_state (int, optional) – Random seed.

n_features_out_

Number of output features.

Type:

int

Examples

>>> transformer = HydraTransformer(n_kernels=8, n_groups=64)
>>> X_transformed = transformer.fit_transform(X_train)

Notes

HYDRA can be combined with ROCKET/MiniROCKET for improved accuracy. A single hyperparameter controls the trade-off between dictionary-like and ROCKET-like behavior.

References

Dempster, A., et al. (2023). “HYDRA: Competing convolutional kernels for fast and accurate time series classification.”

fit(X, y=None)[source]

Fit HYDRA transformer.

transform(X)[source]

Transform time series using HYDRA.

Return type:

ndarray

class endgame.timeseries.RocketClassifier(n_kernels=10000, normalize=True, alphas=None, random_state=None)[source]

Bases: BaseEstimator, ClassifierMixin

ROCKET classifier for time series classification.

Combines ROCKET transform with RidgeClassifierCV for fast and accurate time series classification.

Parameters:
  • n_kernels (int, default=10000) – Number of random kernels.

  • normalize (bool, default=True) – Whether to normalize input.

  • alphas (array-like, optional) – Regularization values to try in RidgeClassifierCV. Default: np.logspace(-3, 3, 10).

  • random_state (int, optional) – Random seed.

classes_

Unique class labels.

Type:

ndarray

transformer_

Fitted ROCKET transformer.

Type:

RocketTransformer

classifier_

Fitted classifier.

Type:

RidgeClassifierCV

Examples

>>> clf = RocketClassifier(n_kernels=10000)
>>> clf.fit(X_train, y_train)
>>> predictions = clf.predict(X_test)
>>> accuracy = clf.score(X_test, y_test)

Notes

This achieves state-of-the-art accuracy on many UCR datasets while being orders of magnitude faster than deep learning approaches.

fit(X, y)[source]

Fit the ROCKET classifier.

Parameters:
  • X (array-like of shape (n_samples, n_timepoints)) – Training time series.

  • y (array-like of shape (n_samples,)) – Target labels.

Returns:

self

predict(X)[source]

Predict class labels.

Parameters:

X (array-like) – Time series to classify.

Return type:

ndarray

Returns:

np.ndarray – Predicted labels.

predict_proba(X)[source]

Predict class probabilities.

Note: RidgeClassifier doesn’t have native predict_proba. This uses decision function with softmax normalization.

Parameters:

X (array-like) – Time series to classify.

Return type:

ndarray

Returns:

np.ndarray of shape (n_samples, n_classes) – Class probabilities.

score(X, y)[source]

Return accuracy score.

Return type:

float

class endgame.timeseries.MiniRocketClassifier(n_kernels=10000, alphas=None, random_state=None)[source]

Bases: BaseEstimator, ClassifierMixin

MiniROCKET classifier for time series classification.

Faster variant of ROCKET using fixed kernels. Up to 75x faster on large datasets while maintaining similar accuracy.

Parameters:
  • n_kernels (int, default=10000) – Number of kernels.

  • alphas (array-like, optional) – Regularization values for RidgeClassifierCV.

  • random_state (int, optional) – Random seed.

Examples

>>> clf = MiniRocketClassifier()
>>> clf.fit(X_train, y_train)
>>> accuracy = clf.score(X_test, y_test)

Notes

Recommended as the default ROCKET variant due to speed and near-deterministic behavior.

fit(X, y)[source]

Fit the MiniROCKET classifier.

predict(X)[source]

Predict class labels.

Return type:

ndarray

predict_proba(X)[source]

Predict class probabilities.

Return type:

ndarray

score(X, y)[source]

Return accuracy score.

Return type:

float

class endgame.timeseries.MultiRocketClassifier(n_kernels=10000, n_features_per_kernel=4, alphas=None, random_state=None)[source]

Bases: BaseEstimator, ClassifierMixin

MultiROCKET classifier for multivariate time series.

Extension of MiniROCKET with additional pooling operations.

Parameters:
  • n_kernels (int, default=10000) – Number of kernels.

  • n_features_per_kernel (int, default=4) – Features per kernel.

  • alphas (array-like, optional) – Regularization values.

  • random_state (int, optional) – Random seed.

fit(X, y)[source]

Fit the MultiROCKET classifier.

predict(X)[source]

Predict class labels.

Return type:

ndarray

predict_proba(X)[source]

Predict class probabilities.

Return type:

ndarray

score(X, y)[source]

Return accuracy score.

Return type:

float

class endgame.timeseries.HydraClassifier(n_kernels=8, n_groups=64, alphas=None, random_state=None)[source]

Bases: BaseEstimator, ClassifierMixin

HYDRA classifier for time series classification.

Combines dictionary methods with ROCKET using competing kernels. Often more accurate than ROCKET alone.

Parameters:
  • n_kernels (int, default=8) – Number of kernels per group.

  • n_groups (int, default=64) – Number of kernel groups.

  • alphas (array-like, optional) – Regularization values.

  • random_state (int, optional) – Random seed.

Examples

>>> clf = HydraClassifier()
>>> clf.fit(X_train, y_train)
>>> accuracy = clf.score(X_test, y_test)
fit(X, y)[source]

Fit the HYDRA classifier.

predict(X)[source]

Predict class labels.

Return type:

ndarray

predict_proba(X)[source]

Predict class probabilities.

Return type:

ndarray

score(X, y)[source]

Return accuracy score.

Return type:

float

class endgame.timeseries.HydraMiniRocketClassifier(hydra_kernels=8, hydra_groups=64, minirocket_kernels=10000, alphas=None, random_state=None)[source]

Bases: BaseEstimator, ClassifierMixin

Combined HYDRA + MiniROCKET classifier.

Concatenates features from both HYDRA and MiniROCKET for improved accuracy. This combination often achieves the best results.

Parameters:
  • hydra_kernels (int, default=8) – HYDRA kernels per group.

  • hydra_groups (int, default=64) – HYDRA kernel groups.

  • minirocket_kernels (int, default=10000) – MiniROCKET kernels.

  • alphas (array-like, optional) – Regularization values.

  • random_state (int, optional) – Random seed.

Examples

>>> clf = HydraMiniRocketClassifier()
>>> clf.fit(X_train, y_train)
>>> accuracy = clf.score(X_test, y_test)

Notes

This combination was shown to significantly improve accuracy over either method alone in the HYDRA paper.

fit(X, y)[source]

Fit the combined classifier.

predict(X)[source]

Predict class labels.

Return type:

ndarray

predict_proba(X)[source]

Predict class probabilities.

Return type:

ndarray

score(X, y)[source]

Return accuracy score.

Return type:

float