Multi-Seasonal Models
AnoFox provides 7 multi-seasonal models across 3 algorithm families: TBATS (trigonometric seasonality with Box-Cox and ARMA errors), MSTL (Loess-based decomposition), and MFLES (median-based, outlier-robust). These models handle data with overlapping seasonal cycles -- for example, hourly data with daily (24), weekly (168), and yearly (8,760) periods simultaneously. MFLES is particularly robust to noisy real-world data, while MFLESX adds exogenous variable support for external predictors.
Multi-seasonal models are forecasting methods that can capture two or more overlapping seasonal cycles simultaneously, such as hourly data with both daily and weekly patterns.
| Model | Description |
|---|---|
TBATS | Trigonometric seasonality, Box-Cox, ARMA errors |
AutoTBATS | Automatic TBATS with parameter selection |
MSTL | Multiple Seasonal-Trend decomposition using Loess |
AutoMSTL | Automatic MSTL with period detection |
MFLES | Median-based Feature-Logic Expert System |
AutoMFLES | Automatic MFLES configuration |
MFLESX | MFLES with exogenous variables |
TBATS
Trigonometric seasonality, Box-Cox transformation, ARMA errors, Trend, and Seasonal components. TBATS is designed specifically for handling complex multiple seasonalities.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
seasonal_periods | INTEGER[] | Yes | Multiple seasonal periods (e.g., [24, 168] for hourly data) |
Example
-- Hourly data with daily (24) and weekly (168) seasonality
SELECT * FROM ts_forecast_by(
'hourly_energy', NULL, timestamp, consumption,
'TBATS', 336, '1h',
MAP{'seasonal_periods': '[24, 168]'}
);
Best for: Multiple seasonal patterns, high-frequency data.
AutoTBATS
Automatic TBATS with parameter selection.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
seasonal_periods | INTEGER[] | auto | Multiple seasonal periods |
Example
SELECT * FROM ts_forecast_by(
'complex_data', NULL, timestamp, value,
'AutoTBATS', 336, '1h',
MAP{}
);
Best for: Multiple seasonality with automatic configuration.
MSTL
Multiple Seasonal-Trend decomposition using Loess, extending the STL method to handle multiple seasonal periods. Decomposes series into trend + multiple seasonal components + remainder.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
seasonal_periods | INTEGER[] | Yes | Multiple seasonal periods |
Example
-- Daily data with weekly (7) and yearly (365) seasonality
SELECT * FROM ts_forecast_by(
'daily_sales', NULL, date, sales,
'MSTL', 90, '1d',
MAP{'seasonal_periods': '[7, 365]'}
);
Best for: Very complex seasonality, decomposition-based forecasting.
AutoMSTL
Automatic MSTL with period detection.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
seasonal_periods | INTEGER[] | auto | Multiple seasonal periods |
Example
SELECT * FROM ts_forecast_by(
'hourly_data', NULL, timestamp, value,
'AutoMSTL', 168, '1h',
MAP{}
);
Best for: Complex seasonality with automatic period detection.
MFLES
Median-based Feature-Logic Expert System. Robust to outliers and noise.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
seasonal_period | INTEGER | auto | Primary seasonal period |
Example
SELECT * FROM ts_forecast_by(
'noisy_retail', NULL, date, sales,
'MFLES', 28, '1d',
MAP{'seasonal_period': '7'}
);
Best for: Noisy data, outliers, real-world messy time series.
AutoMFLES
Automatic MFLES configuration.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
seasonal_period | INTEGER | auto | Seasonal period |
Example
SELECT * FROM ts_forecast_by(
'noisy_data', NULL, date, value,
'AutoMFLES', 28, '1d',
MAP{}
);
Best for: Noisy data with automatic robust forecasting.
Comparison
| Model | Outlier Robust | Speed | Seasonality Handling |
|---|---|---|---|
| TBATS | No | Slow | Trigonometric |
| AutoTBATS | No | Slow | Auto trigonometric |
| MSTL | Moderate | Slow | Loess decomposition |
| AutoMSTL | Moderate | Slow | Auto decomposition |
| MFLES | Yes | Medium | Median-based |
| AutoMFLES | Yes | Medium | Auto median-based |
When to Use Multi-Seasonal Models
| Data Pattern | Recommended Model |
|---|---|
| Hourly + daily + weekly | AutoTBATS or AutoMSTL |
| Daily + weekly + yearly | AutoMSTL |
| Noisy with multiple patterns | AutoMFLES |
| High-frequency (sub-hourly) | AutoTBATS |
| Need decomposition output | MSTL |
Common Seasonal Periods
| Frequency | Common Periods |
|---|---|
| Hourly | 24 (daily), 168 (weekly), 8760 (yearly) |
| Daily | 7 (weekly), 30/31 (monthly), 365 (yearly) |
| Weekly | 52 (yearly) |
| Monthly | 12 (yearly) |
MFLESX
MFLES with exogenous (external) variables. Combines MFLES's robustness to outliers with external predictor support.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
seasonal_period | INTEGER | auto | Primary seasonal period |
Example
-- Create future exogenous values
CREATE TABLE future_exog AS
SELECT * FROM (VALUES
('2024-01-08'::DATE, 22.0, 1),
('2024-01-09'::DATE, 20.0, 0),
('2024-01-10'::DATE, 21.0, 1)
) AS t(date, temperature, promotion);
-- Forecast noisy retail data with exogenous variables
SELECT * FROM ts_forecast_exog_by(
'noisy_retail', NULL, date, sales,
['temperature', 'promotion'],
'future_exog', date, ['temperature', 'promotion'],
'MFLESX', 3,
MAP{}, '1d'
);
Best for: Noisy data with external drivers, real-world messy time series with predictors.
For multi-seasonal data, the choice between TBATS, MSTL, and MFLES depends on data characteristics. TBATS uses trigonometric representations that handle high-frequency periods (e.g., 8,760 for yearly cycles in hourly data) efficiently. MSTL decomposes the series into separate seasonal components via Loess and is effective when you need the decomposition output itself. MFLES uses median-based estimation that resists outlier contamination -- making it the best default for real-world operational data where anomalous observations are common.
See Exogenous Variables for detailed usage
Frequently Asked Questions
How do I determine which seasonal periods to use?
Run ts_detect_periods_by with method='multi' to detect multiple seasonal periods automatically. Common combinations are daily+weekly for hourly data ([24, 168]), weekly+yearly for daily data ([7, 365]), and quarterly+yearly for monthly data ([3, 12]). See the Common Seasonal Periods table for reference values by data frequency.
TBATS is slow on my data. What are faster alternatives?
TBATS can be slow because it searches over multiple model configurations including Box-Cox transformations and ARMA error orders. Try AutoMFLES as a faster alternative that is also more robust to outliers. If you need decomposition output, AutoMSTL is another option. Both run significantly faster than TBATS while handling multiple seasonal periods.
What makes MFLES "robust to outliers"?
MFLES uses median-based estimation instead of mean-based estimation. Medians are inherently resistant to extreme values because a single outlier cannot drag the estimate as far as it would with a mean. This makes MFLES particularly well-suited for real-world operational data where anomalous spikes and drops are common.
Can I use exogenous variables with multi-seasonal models?
Yes, via MFLESX. This variant combines MFLES's outlier robustness and multi-seasonal handling with external predictor support. Use ts_forecast_exog_by and pass your external variable columns. You must provide future values for all exogenous variables covering the full forecast horizon. See the MFLESX section above for a complete example.