Can Machine Learning Actually Predict Sales? Comparing Random Forest and Linear Regression on 4.5M Retail Records

Excerpt: A machine learning study on 4.56 million retail sales records shows Random Forest outperforming Linear Regression by nearly 46%, with recent sales history — not seasonality or pricing — proving the strongest predictor of future demand.

Published on August 3, 2026 5 min read
Can Machine Learning Actually Predict Sales? Comparing Random Forest and Linear Regression on 4.5M Retail Records cover
Every retailer faces the same headache: order too much stock and you're stuck with it; order too little and you're turning customers away. Getting demand forecasting right is one of the highest-leverage problems in retail — and it's exactly what a recent research study set out to solve using machine learning. The study compared two machine learning approaches — Linear Regression and Random Forest — on a massive real-world retail dataset: 4.56 million daily sales records spanning 50 stores, 50 products, and five full years (2019–2023). The goal was simple to state but hard to execute: can a model trained on the past accurately predict sales it's never seen before? The Setup Rather than throwing raw sales numbers at the models, the research focused heavily on feature engineering — turning raw data into signals a model can actually learn from. This included: Calendar features: day of week, month, and day of year, to capture recurring patterns like weekend spikes or holiday demand Lag features: sales from 7 and 30 days prior, since recent history is often the best predictor of what comes next Rolling averages: a 7-day moving average to smooth out day-to-day noise Promotional and pricing data: to capture how discounts and price changes move the needle The models were trained on four years of data (2019–2022) and tested against an entire year they'd never seen (2023) — a setup that mirrors how forecasting actually works in the real world: you only ever have the past to predict the future. The Results The Random Forest model won, and not by a small margin. Model MAE RMSE MAPE R² Linear Regression 1,434 1,730 1.81% 0.9926 Random Forest 771 1,274 0.87% 0.9960 In plain terms: Random Forest cut prediction error nearly in half (a 46% reduction in average error) and nailed sales predictions within less than 1% of actual values on average. Both models explained over 99% of the variance in sales — impressive on its own — but Random Forest was noticeably better at handling the messy, non-linear ways real sales behave, especially during high-volatility periods like the Q4 holiday rush. Why the gap? Linear Regression assumes each factor affects sales independently and additively. But real retail sales don't work that way — a promotion during the holiday season doesn't just add a fixed bump, it multiplies with seasonal demand. Random Forest, being a tree-based ensemble method, naturally captures these interaction effects, while linear models simply can't represent them. What Actually Drives the Predictions Perhaps the most useful finding for practitioners: when the researchers broke down which features mattered most, recent sales history dominated everything else. The 7-day lag and 7-day rolling average were, by a wide margin, the strongest predictors — even more influential than calendar seasonality, pricing, or promotions. The practical takeaway is straightforward: if you're building or maintaining a forecasting system, keeping an accurate, up-to-date window of recent sales data matters more than almost anything else. Fancy features are nice, but a stale or incomplete recent-sales pipeline will hurt your accuracy more than any modeling choice. Why This Matters for Businesses This isn't just an academic exercise — it has direct implications for how retailers and e-commerce businesses approach inventory and demand planning: Random Forest is a strong, accessible starting point. It doesn't require deep learning infrastructure or massive compute — just solid feature engineering and open-source tools. Recent history is king. Investment in clean, real-time sales pipelines pays off more than exotic feature sets. Non-linear models matter during volatile periods. If your business has strong seasonal or promotional swings, a linear model will likely underperform when you need accuracy the most — during peak demand. What's Next The research points to several promising directions for even better forecasting: gradient boosting methods like XGBoost or LightGBM (often a step up from Random Forest), incorporating external signals like weather or economic indicators, and exploring deep learning approaches such as LSTMs or Transformers for even more granular, store-by-store predictions. For now, the takeaway is refreshingly practical: you don't need cutting-edge AI to meaningfully improve forecasting accuracy. Solid feature engineering plus a well-tuned Random Forest model can get you 99%+ accuracy on real-world retail data — a strong foundation for smarter inventory decisions and better bottom lines.
Share this article:

Stay in the Loop

Get the latest articles and insights delivered to your inbox

PyLoom Team