# Time Series Forecasting

> Trend, seasonality, lag features and proper backtesting, from classical models to gradient boosting and deep forecasters. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/time-series-forecasting
Last updated: 2026-11-28

Trend, seasonality, lag features and proper backtesting, from classical models to gradient boosting and deep forecasters.

Intermediate · about 10 hours · difficulty 3/5

Learn first: [Gradient Boosting with XGBoost and LightGBM](https://www.internhack.in/roadmaps/tracks/machine-learning/gradient-boosting), [Cross-Validation](https://www.internhack.in/roadmaps/tracks/machine-learning/cross-validation)

Forecasting demand, traffic, prices or sensor readings is one of the most common business uses of ML, and one of the easiest to get wrong because time breaks the usual assumptions.

### Understand the series first

- Plot it. Look for **trend**, **seasonality** (daily, weekly, yearly), holidays, outliers and structural breaks.
- **Decomposition** separates trend, seasonal and residual parts.
- **Stationarity** and autocorrelation plots (ACF, PACF) guide classical model choices.

### Model options

- **Baselines**: last value, seasonal naive (same day last week) and moving averages. Always report them.
- **Classical**: exponential smoothing (ETS) and ARIMA/SARIMA, strong on single series with clear patterns.
- **ML on features**: build **lag features**, rolling statistics and calendar features, then use gradient boosting. This wins many competitions and works across many related series.
- **Deep and foundation models**: N-BEATS, temporal fusion transformers and pretrained forecasting models for large collections of series.

### Evaluation without cheating

Never shuffle. Use **rolling-origin backtesting** (train up to time t, forecast the next horizon, move forward, repeat). Compute rolling features using only past data. Choose metrics that match the business: MAE, RMSE, MAPE (breaks near zero) or MASE, and produce **prediction intervals**, not just point forecasts.

**Good enough to move on** when you can beat a seasonal naive baseline in a proper backtest and explain which features could have leaked future information.

## Key concepts

- **Trend and seasonality decomposition**
- **Naive and seasonal baselines**
- **ARIMA and exponential smoothing**
- **Lag and rolling features**
- **Rolling-origin backtesting**
- **Forecast metrics (MAE, MAPE, MASE)**
- **Prediction intervals**
- **Deep forecasting models**

## Mini project

Forecast daily sales or energy demand 14 days ahead: compare seasonal naive, ETS and LightGBM with lag features in a 6-fold rolling backtest, and plot forecasts with 80 percent intervals.

## Check yourself

Why is a random K-fold split invalid for time series, and how does rolling-origin evaluation fix it?

## Free resources

- [Forecasting: Principles and Practice](https://otexts.com/fpp3/) (OTexts)
- [TensorFlow: time series forecasting tutorial](https://www.tensorflow.org/tutorials/structured_data/time_series) (TensorFlow)
- [Kaggle Learn: Time Series](https://www.kaggle.com/learn/time-series) (Kaggle)

Previous: [Recommender Systems](https://www.internhack.in/roadmaps/tracks/machine-learning/recommender-systems) · Next: [Reinforcement Learning Fundamentals](https://www.internhack.in/roadmaps/tracks/machine-learning/reinforcement-learning-basics)

## More in Recommenders, Time Series and Reinforcement Learning

- [Recommender Systems](https://www.internhack.in/roadmaps/tracks/machine-learning/recommender-systems)
- [Time Series Forecasting](https://www.internhack.in/roadmaps/tracks/machine-learning/time-series-forecasting)
- [Reinforcement Learning Fundamentals](https://www.internhack.in/roadmaps/tracks/machine-learning/reinforcement-learning-basics)
- [Deep Reinforcement Learning](https://www.internhack.in/roadmaps/tracks/machine-learning/deep-reinforcement-learning)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
