Time series forecasting using linear regression with seasonal features.
Fits a polynomial trend (degree 2) plus Fourier seasonal terms whose periods are automatically chosen based on the data's sampling interval:
- Sub-hourly data (e.g. 5-min) → daily + half-daily periods (operational monitoring)
- Hourly data → daily + weekly periods
- Daily data → weekly + yearly periods (capacity planning)
Periods can also be set explicitly via the :periods option (list of seconds).
Uses the normal equation (X'X)⁻¹X'y — no external ML libraries needed.
Summary
Functions
Auto-detect seasonal periods based on median sampling interval.
Fit a model to data and return predictions for the training data itself. Used by anomaly detection to compute residuals.
Predict future values from historical time series data.
Functions
Auto-detect seasonal periods based on median sampling interval.
Returns a list of period lengths in seconds:
- Interval < 1 hour →
[86400, 43200](daily + half-daily) - Interval 1h–23h →
[86400, 604800](daily + weekly) - Interval >= 1 day →
[604800, 31_536_000](weekly + yearly)
Fit a model to data and return predictions for the training data itself. Used by anomaly detection to compute residuals.
Options
:periods- List of seasonal period lengths in seconds (default: auto-detected from sampling interval)
Predict future values from historical time series data.
Parameters
data- List of{timestamp, value}tuplesopts- Options::horizon- Seconds to forecast ahead (required):bucket- Seconds between forecast points (default: inferred from data):periods- List of seasonal period lengths in seconds (default: auto-detected from sampling interval)
Returns {:ok, [{future_timestamp, predicted_value}, ...]} or {:error, reason}.