Back to Blog
Machine Learning January 5, 2025 9 min read

Time Series Forecasting at Scale: From ARIMA to LightGBM

When classical time series methods work and when ML wins — feature engineering for time series, backtesting frameworks, and handling seasonality in production.

Method Selection

ScenarioBest Method
Few series, clean dataProphet, SARIMA
Many series (1000+)LightGBM with lag features
Complex seasonalityN-BEATS, TFT
Real-time, low latencySimple exponential smoothing

LightGBM for Time Series

def make_features(df, lags=[1,7,14,28], windows=[7,14,28]):
    for lag in lags:
        df[f'lag_{lag}'] = df['target'].shift(lag)
    for w in windows:
        df[f'rolling_mean_{w}'] = df['target'].shift(1).rolling(w).mean()
        df[f'rolling_std_{w}'] = df['target'].shift(1).rolling(w).std()
    df['day_of_week'] = df.index.dayofweek
    df['month'] = df.index.month
    df['is_weekend'] = (df.index.dayofweek >= 5).astype(int)
    return df

Backtesting Framework

Walk-forward validation: train on [0..t], predict [t+1..t+h], slide forward.

Time SeriesForecastingLightGBMProphetFeature Engineering
O

Ossama Elhakki

AI Engineer & ML Systems Builder — Morocco