Sales Forecasting¶
Predicting future sales is one of the most directly valuable things a data scientist can do for a business. Every additional percentage point of forecast accuracy translates to less overstock, fewer stockouts, better staffing decisions, and tighter budgets. This project teaches you to approach time series forecasting as a feature engineering problem — transforming a date column into meaningful signals that a standard regression model can learn from.
Why This Matters¶
Retailers order inventory weeks in advance. Warehouses plan labor based on expected shipments. Finance teams build annual budgets from monthly forecasts. In every case, the underlying question is the same: given everything we know up to today, what will sales look like tomorrow, next week, or next month?
This is not a toy problem. It is the core task of demand planning, and it is one of the highest-ROI applications of machine learning in industry.
Learning Objectives¶
By completing this project you will be able to:
- Generate and understand a realistic synthetic time series dataset with trend, seasonality, and noise components
- Perform EDA specific to time series: decomposition, autocorrelation, seasonal patterns
- Engineer calendar features (day of week, month, quarter, is_weekend) that encode temporal structure
- Create lag features and rolling window features without introducing data leakage
- Apply the correct train-test split for time series data — ordered in time, never shuffled
- Fit and compare Random Forest and Gradient Boosting regressors on time series data
- Use TimeSeriesSplit for cross-validation instead of standard KFold
- Evaluate forecasts with MAE, RMSE, MAPE, and visual diagnostics
- Interpret feature importance to understand what the model actually learned
Skills Practiced¶
| Skill Area | Specific Techniques |
|---|---|
| Data Generation | Synthetic time series with trend, weekly and annual seasonality, noise |
| EDA | Time plots, seasonal decomposition, autocorrelation analysis |
| Feature Engineering | Calendar features, lag features, rolling statistics, one-hot encoding |
| Modelling | Random Forest, Gradient Boosting, naive baselines |
| Cross-Validation | TimeSeriesSplit — time-aware evaluation |
| Evaluation | MAE, RMSE, MAPE, residual plots, feature importance, error by segment |
Prerequisites¶
- Week 02 Day 01 Part 2 — Regression Algorithms (Random Forest, Gradient Boosting, regression metrics)
- Week 02 Day 03 Part 1 — Feature Engineering (encoding, transformations, lag features)
- Week 02 Day 01 Part 1 — Scikit-learn workflow (fit, predict, cross-validation)
- Week 01 Day 02 — Pandas (datetime indexing, groupby, rolling)
Project Structure¶
| File | What it covers |
|---|---|
README.md |
Project overview, objectives, prerequisites |
dataset-guide.md |
Synthetic data generation, column reference, data components |
eda.md |
Time plots, seasonal patterns, autocorrelation, key findings |
feature-engineering.md |
Calendar features, lag features, rolling features, correct train-test split |
model-building.md |
Baselines, Random Forest, Gradient Boosting, TimeSeriesSplit, model comparison |
evaluation.md |
Actual vs predicted, MAPE, error by segment, feature importance, limitations |
interview-questions.md |
Eight interview questions with model answers |
Dataset¶
Synthetic daily sales data for four product categories (Electronics, Clothing, Food, Home) spanning 2021–2023. No download required — you generate it with a single code block. The data includes a realistic growth trend, weekly seasonality (weekday vs. weekend), annual seasonality (Q4 peak, Q1 trough), and random noise.
Warning
Never randomly shuffle time series data. The temporal ordering of observations is not just metadata — it is the fundamental structure of the problem. If you shuffle rows before splitting into train and test, future data leaks into your training set and your evaluation is meaningless. Every split in this project respects chronological order.
Info
This project focuses on the feature engineering approach to forecasting: transform time into tabular features, then use a standard regression model. Classical methods like ARIMA and Prophet exist and are powerful, but they require different assumptions and are covered separately. The ML approach scales better to multiple series and handles non-stationarity through features rather than explicit modeling.