Sales forecasting is the most requested data science use case in business. In this complete tutorial, we build a forecasting model end-to-end with Python: from data exploration to production deployment.
The complete pipeline
A time series forecasting project always follows the same pipeline: exploration, preprocessing, model selection and training, evaluation, deployment and monitoring.
Step 1: exploration and diagnostics
Visualise your data first. Identify trend, seasonality (annual, weekly, daily), outliers and structural breaks. Test stationarity with the ADF test.
Step 2: choose the right model
Prophet (Meta): our default recommendation
Prophet is robust, easy to configure and natively handles missing data, holidays and trend changes. Our starting point for 80% of sales forecasting cases.
LightGBM with temporal features
For series with many explanatory variables (weather, price, promotions), gradient boosting with temporal features (lag variables, rolling averages) often outperforms classical models.
Anti-pattern to avoid: never train on future data. Train/test split on time series must respect chronological order. Use TimeSeriesSplit from scikit-learn.
Step 3: correct evaluation
MAPE for comparison between different volume products. MAE for absolute average error. RMSE to penalise large errors.
Production with confidence intervals
Always communicate confidence intervals in production, not just a point forecast. '1,200 units with 90% probability in range [950, 1,450]' is infinitely more useful than simply '1,200'.
With care,
Excellent article, this matches exactly what we're seeing with our enterprise clients. The section on inference costs is especially valuable. It's a topic most articles gloss over but it's make-or-break at scale.
Thanks James! Inference cost optimization is often deprioritized during prototyping but becomes critical in production. Feel free to book a session if you'd like to go deeper on this.
Sharing this with my whole team. The distinction between an impressive demo and robust production is exactly the debate we're having internally right now. The human checkpoint advice is immediately actionable.
Great article. I'd push back slightly on the 18-day deployment estimate, in our experience with enterprise security and GDPR requirements, 4–6 weeks is more realistic for a first production agent.
Completely fair point David. The 18 days refers to a scoped first agent in a test environment. For full enterprise production with security constraints, your estimate is accurate.