A robust MLOps pipeline for retail sales forecasting designed for retail data scientists and ML engineers.
In retail, accurate demand forecasting is critical for optimizing inventory, staff scheduling, and financial planning. This project provides a production-ready sales forecasting solution that can be immediately deployed in retail environments to:
- Predict future sales volumes across multiple stores and products
- Capture seasonal patterns and trends in customer purchasing behavior
- Support data-driven inventory management and purchasing decisions
- Provide actionable insights through visual forecasting dashboards
The pipeline works with time-series retail sales data structured as follows:
| Field | Description |
|---|---|
| date | Date of sales record (YYYY-MM-DD) |
| store | Store identifier (e.g., Store_1, Store_2) |
| item | Product identifier (e.g., Item_A, Item_B) |
| sales | Number of units sold |
| price | Unit price |
The system automatically handles:
- Multiple store/item combinations as separate time series
- Train/test splitting for model validation
- Proper data transformations required by Prophet
- Missing value imputation and outlier detection
The project includes two primary pipelines:
The training pipeline performs the following steps:
- Data Loading: Imports historical sales data from CSV files
- Data Preprocessing:
- Transforms data into Prophet-compatible format
- Creates separate time series for each store-item combination
- Performs train/test splitting based on configurable ratio
- Model Training:
- Trains multiple Facebook Prophet models simultaneously, one for each store-item combination
- Configures seasonality parameters based on domain knowledge
- Handles price changes as regressors when available
- Model Evaluation:
- Calculates MAPE, RMSE, and MAE metrics on test data
- Generates visual diagnostics for model performance
- Forecasting:
- Produces forecasts with uncertainty intervals
- Creates interactive HTML visualizations
The inference pipeline enables fast forecasting with pre-trained models:
- Data Loading: Imports the most recent sales data
- Data Preprocessing: Transforms data into Prophet format
- Forecasting: Generates predictions using production models
- Visualization: Creates interactive dashboards with forecasts
The forecasting solution uses Facebook Prophet, chosen specifically for its combination of accuracy and simplicity in retail forecasting scenarios:
- Multiple Models Approach: Rather than a one-size-fits-all model, we generate individual Prophet models for each store-item combination, allowing forecasts that capture the unique patterns of each product in each location
- Components: Prophet automatically decomposes time series into trend, seasonality, and holidays
- Seasonality: Captures weekly, monthly, and yearly patterns in sales data
- Special Events: Handles holidays and promotions as custom seasonality effects
- Uncertainty Estimation: Provides prediction intervals for better inventory planning
- Extensibility: Supports additional regressors like price and marketing spend
Prophet was selected for this solution because it excels at:
- Handling missing data and outliers common in retail sales data
- Automatically detecting seasonal patterns without extensive feature engineering
- Providing intuitive parameters that business users can understand
- Scaling to thousands of individual time series efficiently
The project leverages ZenML's MLOps framework to provide:
- Model Versioning: Track all model versions and their performance metrics
- Reproducibility: All experiments are fully reproducible with tracked parameters
- Pipeline Caching: Speed up experimentation with intelligent caching of pipeline steps
- Artifact Tracking: All data and models are properly versioned and stored
- Deployment Ready: Models can be directly deployed to production environments
A key innovation in this project is the custom ProphetMaterializer that enables serialization/deserialization of Prophet models for ZenML artifact storage.
- Python 3.9+
- ZenML installed and configured
# Clone the repository
git clone https://github.com/zenml-io/zenml-projects.git
cd zenml-projects/retail-forecast
# Install dependencies
pip install -r requirements.txt
# Initialize ZenML (if needed)
zenml initTo train models and generate forecasts:
# Run the training pipeline (default)
python run.py
# Run with custom parameters
python run.py --forecast-periods 60 --test-size 0.3 --weekly-seasonality TrueTo make predictions using existing models:
# Run the inference pipeline
python run.py --inferenceStart the ZenML dashboard:
zenml loginNavigate to the dashboard to explore:
- Pipeline runs and their status
- Model performance metrics
- Interactive forecast visualizations
- Version history of all models
This solution can be integrated with existing retail systems:
- Inventory Management: Connect forecasts to automatic reordering systems
- ERP Systems: Feed forecasts into financial planning modules
- BI Dashboards: Export forecasts to Tableau, Power BI, or similar tools
- Supply Chain: Share forecasts with suppliers via API endpoints
A retail chain with 50 stores and 500 products uses this pipeline to:
- Train models on 2 years of historical sales data
- Generate daily forecasts for the next 30 days for each store-item combination
- Aggregate forecasts to support central purchasing decisions
- Update models weekly with new sales data
The result: 15% reduction in stockouts and 20% decrease in excess inventory.




