Forecast monthly chocolate sales using historical transactions.
This project builds and evaluates forecasting models using a time-aware workflow, then generates 2025 forecasts for :
- Total Revenue (
total_revenue) - Total Boxes Shipped (
total_boxes)
The final models are trained on 2022–2023 data and tested on 2024. After validation, the project produces month-by-month forecasts for 2025.
Problem statement :
How can we use historical chocolate sales data to predict future demand (revenue and volume) to support better planning and reduce stockouts/overstock?
Targets :
- Monthly total revenue
- Monthly total boxes shipped
Forecast horizon :
- Full year 2025 (12 months)
-
Source : Kaggle Chocolate Sales dataset.
-
Key columns used :
DateCountryAmount(revenue)Boxes Shipped(volume)
The pipeline aggregates transactions into monthly totals per country and engineers lag-based features for forecasting.
- Parse dates into datetime
- Convert
Amountfrom currency format to numeric - Create derived metric
Amount_per_box - Explore trends/seasonality and country/product contributions
To use scikit-learn for forecasting, time series data is transformed into a supervised learning table with :
- Lag features:
rev_lag_1,rev_lag_2,box_lag_1,box_lag_2 - Seasonality features:
month_num,month_sin,month_cos - Categorical encoding: One-hot encoding for
country
Time-based split :
- Train: 2022–2023
- Test: 2024
Models compared :
- Naive baseline (lag-1)
- Ridge regression (with seasonality)
- HistGradientBoostingRegressor (final choice)
Forecasts are generated recursively month-by-month for 2025:
- Each month prediction becomes part of the history to compute next month lags.
- RMSE (Root Mean Squared Error)
- MAPE (Mean Absolute Percentage Error)
Where:
-
$y_i$ is the true value,$\hat{y}_i$ is the predicted value, and$n$ is the number of observations.
Final selected model: HistGradientBoostingRegressor
- Revenue forecast MAPE: ~14.38%
- Boxes forecast MAPE: ~14.89%
- The final HistGradientBoosting models achieved ~14% MAPE on 2024 data and were used to generate 2025 forecasts.
.
├── data/
│ ├── chocolate_sales.csv # raw dataset (local)
│ ├── processed_data.csv # cleaned dataset (from EDA)
│ └── monthly_data.csv # monthly aggregated modeling table
│
├── models/
│ ├── hgb_revenue.joblib # final model for revenue
│ ├── hgb_boxes.joblib # final model for boxes
│ └── features.json # exact feature list/order used in training
│
├── notebooks/
│ ├── 01_eda.ipynb # cleaning + exploration
│ ├── 02_modeling.ipynb # feature engineering + training + evaluation
│ └── 03_forecast_2025.ipynb # load models + generate 2025 forecasts
│
├── outputs/
│ └── forecast_2025.csv # final predictions for 2025
│
├── README.md
└── requirements.txt
pip install -r requirements.txt-
notebooks/01_eda.ipynb- Outputs:
data/processed_data.csv
- Outputs:
-
notebooks/02_modeling.ipynb- Outputs:
data/monthly_data.csvmodels/hgb_revenue.joblibmodels/hgb_boxes.joblibmodels/features.json
- Outputs:
-
notebooks/03_forecast_2025.ipynb- Outputs:
outputs/forecast_2025.csv
- Outputs:


