Time Series Forecasting for Beginners: Methods, Steps and Python Example
On this page
Short answer: Time series forecasting predicts future values (sales, demand, website traffic) from past values ordered in time. The beginner workflow is: (1) plot the data and identify trend and seasonality; (2) build a simple baseline (e.g. last week’s value); (3) try classic models such as exponential smoothing or ARIMA, or machine learning with lag features; (4) validate with time-based splits (train on the past, test on the future); and (5) compare models with MAE or MAPE. A model is only useful if it beats the baseline.
Key takeaways
- Never shuffle time series data when splitting.
- Always start with a naive baseline.
- Understand trend, seasonality and holidays before modelling.
- ML models need lag and calendar features.
Key concepts
| Concept | Meaning |
|---|---|
| Trend | Long-term increase or decrease |
| Seasonality | Regular repeating patterns (weekly, monthly, festive seasons) |
| Noise | Random variation |
| Stationarity | Statistical properties don’t change over time (needed by some models like ARIMA) |
| Lag | A past value used as a feature (e.g. sales 7 days ago) |
| Horizon | How far ahead you forecast |
Forecasting methods, simplest first
| Method | Idea | Good for |
|---|---|---|
| Naive / seasonal naive | Next value = last value (or same day last week) | Baselines |
| Moving average | Average of recent periods | Smoothing, simple forecasts |
| Exponential smoothing (Holt-Winters) | Weighted recent values with trend and seasonality | Clear seasonal patterns |
| ARIMA / SARIMA | Models autocorrelation; seasonal version handles seasonality | Single series with stable patterns |
| Machine learning (XGBoost etc.) | Predict from lag, rolling and calendar features | Many related series, external drivers |
| Deep learning (LSTM, transformers) | Learn complex temporal patterns | Large datasets |
Python example: baseline vs Holt-Winters
import pandas as pd
from statsmodels.tsa.holtwinters import ExponentialSmoothing
from sklearn.metrics import mean_absolute_error
df = pd.read_csv('daily_sales.csv', parse_dates=['date']).set_index('date').asfreq('D')
y = df['sales'].ffill()
train, test = y[:-28], y[-28:] # last 4 weeks as test
# seasonal naive baseline: same day last week
baseline = y.shift(7)[-28:]
print('Baseline MAE:', mean_absolute_error(test, baseline))
hw = ExponentialSmoothing(train, trend='add', seasonal='add', seasonal_periods=7).fit()
forecast = hw.forecast(28)
print('Holt-Winters MAE:', mean_absolute_error(test, forecast))
Machine learning with lag features
feat = pd.DataFrame({'sales': y})
for lag in [1, 7, 14]:
feat[f'lag_{lag}'] = feat['sales'].shift(lag)
feat['rolling_7'] = feat['sales'].shift(1).rolling(7).mean()
feat['dayofweek'] = feat.index.dayofweek
feat['month'] = feat.index.month
feat = feat.dropna()
Notice the shift(1) before rolling: features must use only information available before the forecast date, otherwise you leak the future. See feature engineering and XGBoost explained.
Validating forecasts correctly
- Use a hold-out period at the end, or rolling-origin (walk-forward) validation
- scikit-learn’s
TimeSeriesSplitcreates expanding train windows - Test over the same horizon you’ll forecast in production
Forecast metrics
| Metric | Note |
|---|---|
| MAE | Average absolute error in business units; easy to explain |
| RMSE | Penalises large misses more |
| MAPE | Percentage error; unstable when actual values are near zero |
Practical tips
- Add holiday and festival indicators (Diwali, year-end sales) where relevant
- Include known future drivers such as promotions or price changes
- Forecast ranges (prediction intervals), not just single numbers
- Re-train regularly as new data arrives and monitor accuracy
Frequently asked questions
Which forecasting method should beginners start with?
Start with a seasonal naive baseline, then exponential smoothing. Move to ARIMA or ML once you understand the data.
Can I use random train-test splits?
No. Random splits leak future information into training and give over-optimistic results.
How much history do I need?
Enough to cover several seasonal cycles. For yearly seasonality, ideally a few years of data.
Is forecasting used in data science jobs?
Yes: demand planning, inventory, finance, staffing and marketing all rely on forecasting.
Conclusion
Time series forecasting starts with understanding trend and seasonality, beating a naive baseline, and validating honestly on future periods. Master these steps with classic and ML methods, and you can build forecasts businesses actually trust.
Build forecasting projects hands-on in our Data Science course.
Learn with Mehul Prajapati in Borivali West
At Mehul Prajapati’s institute, you get 100% practical, hands-on training by industry experts with a minimum of 5+ years of experience, plus job-oriented programmes with placement support. Weekday and weekend batches are available, with multiple 2-hour slots between 8 am and 6 pm.
Address: 12th Floor, 1214, Gold Crest Business Centre, LT Rd, Above Westside Showroom, Borivali West, Mumbai, Maharashtra 400092
Call: +91 99301 12627 / +91 96645 45072
Visit the centre or call us to choose the right course and batch and to know the current fee structure.