1. Introduction
Anyone who has run a small shop knows the problem: you never really know how much to buy. Order too much milk and half of it spoils before it sells. Order too little and you are turning away customers by Wednesday. Most small and medium-sized retailers still make these decisions by gut feeling - checking what sold last week, maybe adjusting for a holiday, and hoping for the best. It works, sort of, but the mistakes add up fast, especially with perishable goods, where a bad guess means thrown-away inventory, not just a missed sale.
This is the problem this project addresses: can machine learning improve on manual demand estimation for small retailers, and if so, which forecasting method works best? We compare three approaches of increasing complexity - ARIMA as a classical time-series baseline, Random Forest as a feature-based machine learning model, and an LSTM neural network as a deep-learning approach - to see how each handles different kinds of products, since a steady seller such as rice behaves very differently from something promotion-driven such as snacks.
Classical time-series forecasting has long relied on the Box-Jenkins ARIMA methodology (Box, Jenkins, & Reinsel, 1994), valued for its simplicity and interpretability, and still commonly used as a baseline in retail forecasting studies (da Veiga, Da Veiga, Catapan, Tortato, & Da Silva, 2014). Machine learning approaches such as Random Forest (Breiman, 2001) have been applied successfully to retail sales forecasting (Deepak, Sathyanarayanan, & Arunnehru, 2025), often outperforming classical baselines by exploiting engineered features such as lagged sales and promotions. Deep learning methods, particularly LSTM networks (Hochreiter & Schmidhuber, 1997), have been used for sequential forecasting problems, with mixed results relative to classical and ensemble methods depending on data volume and seasonality (Menculini et al., 2021; Bousqaoui, Slimani, & Achchab, 2021). Punia, Nikolopoulos, Singh, Madaan, and Litsiou (2020) directly compared LSTM and Random Forest for multi-channel retail demand forecasting, finding that the better-performing model varied with data characteristics - a pattern also observed in this study. Retail forecasting is further complicated by promotional effects (Hewage & Bandara, 2026) and holiday effects, both of which introduce irregular demand spikes that purely statistical models struggle to capture. Much of the existing literature compares only two forecasting families at a time; this study addresses that gap with a documented, three-way, per-category comparison built specifically for a small-retailer forecasting tool.
To build and test the system, a combined dataset of just over 200,000 sales records was used - the Favorita Grocery Sales Forecasting dataset from Kaggle, together with TahlilchiAI’s own retail sales history. After cleaning the data and engineering features such as lagged sales, rolling averages, and day-of-week patterns, all three models were trained on the same time-based split and compared using MAE, RMSE, and MAPE.
The remainder of this paper is organized as follows. Section 2 describes the data and methods. Section 3 presents the results. Section 4 discusses what the results mean, along with the study's limitations, and Section 5 gives the conclusion and directions for future work.
2. Methods
2.1 Data
The primary data source was the Favorita Grocery Sales Forecasting dataset (Kaggle), supplemented with synthetic daily sales data - generated using trend, weekly, and yearly seasonality components plus random noise - to fill short gaps in item history. Every row was tagged with a source column (real or synthetic) so synthetic rows could be excluded from evaluation. The unit of analysis is one store/item pair on one calendar day, with columns for store and item identifiers, date, sales quantity (the forecasting target), unit price, promotion and holiday flags, stock on hand, and product category. Cleaning rules included converting dates to ISO 8601 format, flagging negative or impossible values, merging duplicate rows, forward-filling missing prices, converting placeholder codes to missing values, and flagging statistical outliers for review.
2.2 Preprocessing
Time-aware features were engineered per store/item series: the previous day’s sales, the same weekday one week prior, a trailing 7-day mean and standard deviation, and calendar features (day of week, month). These were computed after grouping by store and item and shifting values forward before computing rolling statistics, to prevent same-day leakage. Categorical variables were one-hot encoded (category) or frequency encoded (store/item identifiers), and numeric columns were scaled with a StandardScaler fit on the training split only. The dataset was split chronologically - never shuffled - into training (70%), validation (15%), and test (15%) sets.
2.3 Models and Evaluation
ARIMA. Stationarity was assessed with the Augmented Dickey-Fuller test, with differencing applied until the p-value fell below 0.05. Autoregressive and moving-average orders were selected using ACF/PACF plots, and one ARIMA model was fit per store/item series rather than a single shared model.
Random Forest. Forecasting was reframed as supervised learning, with lag, rolling, calendar, and promotion/holiday features as inputs and sales quantity as the target. A RandomForestRegressor was fit with n_estimators=300, max_depth=8, and min_samples_leaf=3, selected via grid search using walk-forward (TimeSeriesSplit) cross-validation to avoid training on future data.
LSTM. Sliding windows of 14 days were used as input, with each window’s next day as the prediction target. The architecture consisted of two stacked LSTM layers (64 units, then 32 units) followed by a dense output layer, trained with the Adam optimizer and mean-squared-error loss. Sales values were scaled to a 0-1 range with a MinMaxScaler fit on the training split only. Training used early stopping (monitoring validation loss, patience of 5 epochs, restoring best weights); validation loss stopped improving around epoch 22 for the representative series tested, which is where training was halted.
Evaluation. All models were assessed with Mean Absolute Error (MAE), Root Mean Squared Error (RMSE), and Mean Absolute Percentage Error (MAPE), computed on the identical held-out test period for every model and category, to ensure a fair comparison. Each experiment was repeated 12 times to check the stability of results, not just a single score.
3. Results
Table 1 reports test-set MAPE for all three models across five product categories, evaluated on the same held-out test period per category.
| Category | ARIMA | Random Forest | LSTM | Best model |
| Grocery | 9.8% | 6.9% | 6.1% | LSTM |
| Household | 11.2% | 7.4% | 8.0% | Random Forest |
| Electronics | 14.5% | 9.8% | 12.1% | Random Forest |
| Beverages | 8.1% | 6.5% | 5.4% | LSTM |
| Personal Care | 12.9% | 8.7% | 9.9% | Random Forest |
Table 1. Test MAPE by category and model (lower is better).
LSTM achieved the lowest MAPE in two of five categories (Grocery, Beverages); Random Forest achieved the lowest MAPE in the remaining three (Household, Electronics, Personal Care). ARIMA did not achieve the lowest MAPE in any category tested. Repeating each experiment 12 times to check stability showed that ARIMA had the tightest spread of results but the highest (worst) average MAPE; Random Forest combined a low median MAPE with a comparatively tight spread; LSTM showed the widest spread of the three models despite producing the single best MAPE in two categories.
Based on these results and a tie-break rule preferring the simpler model when results fall within 0.5 percentage points, the following per-category model registry was built for the TahlilchiAI application: Grocery → LSTM (6.1%), Household → Random Forest (7.4%), Electronics → Random Forest (9.8%), Beverages → LSTM (5.4%), Personal Care → Random Forest (8.7%).
4. Discussion
LSTM’s advantage appears strong in the two categories with the longest, most seasonally consistent histories - Grocery and Beverages - which makes sense as LSTM needs a long run of history before it has enough to learn from. In categories with less historical data - Household, Electronics, and Personal Care - Random Forest’s feature-based approach proved more effective, likely because engineered lag and promotion features carry more usable signal than a full sequence does when the history is short. ARIMA never won a category, which is not surprising since it cannot use promotion or holiday information directly without extension to SARIMAX, but it was the most stable model across repeated runs.
This pattern is broadly consistent with Punia et al. (2020), who found that the relative performance of LSTM and Random Forest depends on the characteristics of the data rather than one model consistently outperforming the other. In our experiments, LSTM achieved the best MAPE for the Grocery and Beverages categories, but its performance also varied more across repeated runs than Random Forest's. This suggests a trade-off between accuracy and consistency. For retailers who retrain forecasting models regularly, a slightly more stable model may be preferable to one that occasionally achieves the lowest error but produces less consistent results over time.
4.1 Limitations
Several limitations should be considered when interpreting these results. Some categories, such as Electronics, showed noticeably higher error across every model, suggesting shorter or spikier histories than Grocery or Beverages, so the comparison may not generalize to categories with even less history. Synthetic data was used to fill short gaps during data collection. Results may be slightly optimistic if some synthetic observations were unintentionally included in the evaluation dataset. Only a limited grid search was used to tune the Random Forest model, so it is possible that better hyperparameter combinations were not explored. LSTM also produced more variable results across repeated training runs than the other models. While it often achieved the best accuracy, its performance was not as consistent.
5. Conclusion and Future Work
This project asked whether machine learning could improve on manual demand estimation for small retailers, and which approach works best across product categories. The optimal forecasting model differed by product category: LSTM produced the most accurate forecasts for long-history, strongly seasonal categories, while Random Forest performed best for shorter or spikier categories and showed a better balance of accuracy and stability overall. Instead of committing to a single algorithm, TahlilchiAI’s forecasting pipeline relies on a saved model registry that routes each category to its best model. Future work includes extending SARIMAX to model promotions and holidays directly within the ARIMA family, testing on additional categories and stores, and validating the system with live A/B testing inside the application.
