How Machine Learning Predicts Stockouts 3 Weeks Before They Happen
A mid-size beauty retailer running about 3,500 SKUs had a persistent problem. Every month, 8-12% of their top-selling products would hit zero inventory before replenishment arrived. Each stockout on a popular item cost them an estimated $2,800 per day in lost sales, not counting the customer goodwill damage and the ad spend wasted driving traffic to out-of-stock product pages.
Their inventory team was checking stock levels daily and placing reorders when inventory hit a predetermined threshold. The problem was that the threshold was static, a fixed number of units based on average daily sales over the past 90 days. When demand spiked due to a viral TikTok mention or a competitor going out of stock on a similar product, the static threshold could not react fast enough.
Why Static Reorder Points Fail
A static reorder point assumes that future demand will look like past demand and that supplier lead times are consistent. Both assumptions break down regularly. Demand for individual SKUs in ecommerce is lumpy. A product might sell 20 units per day for three weeks and then suddenly sell 60 units per day because an influencer mentioned it, a competitor raised their price, or a seasonal shift kicked in. By the time you notice the acceleration in your daily inventory check, you might already be two weeks into elevated demand with a three-week supplier lead time ahead of you.
Supplier lead times are equally variable. A supplier who normally delivers in 14 days might take 21 days during their busy season, after a raw material shortage, or due to shipping delays. If your reorder point assumes 14-day lead time and the actual lead time is 21 days, you have a seven-day gap where you are selling inventory you thought would already be replenished.
What the ML Model Watches
A stockout prediction model processes multiple data streams simultaneously. The primary input is sales velocity, not as a simple average but as a time-series with trend and seasonality components. The model detects acceleration (selling faster than last week), deceleration, and cyclical patterns specific to each SKU.
Inventory position (current stock on hand plus units in transit minus units allocated to pending orders) gives the model the supply side of the equation. Combined with predicted demand, the model calculates an estimated days-of-supply metric that updates dynamically.
Supplier performance data adds a crucial dimension. By tracking actual vs. expected delivery dates for each supplier over time, the model builds a distribution of likely lead times rather than using a single point estimate. If Supplier A delivers in 12-18 days with a median of 14, the model uses the full distribution when calculating stockout probability.
External signals provide early warning of demand shifts. Search volume for the product or category on Google, mentions on social media, competitor stock levels (often detectable through their product pages showing limited availability), and seasonal calendars all feed into the demand forecast. A sudden spike in Google search volume for a product often precedes a sales spike by 5-10 days, which gives the model an early signal that the current inventory trajectory may not hold.
The Three-Week Warning Window
The model outputs a stockout probability for each SKU at various time horizons: 7 days, 14 days, and 21 days out. A typical alert might look like this: SKU #4892 (Vitamin C Serum 30ml) currently has 340 units on hand. At current sales velocity of 28 units per day, stock depletes in approximately 12 days. However, demand trend shows 15% week-over-week acceleration. Adjusted depletion estimate is 9 days. Next replenishment shipment of 500 units has expected arrival in 16 days based on supplier lead time distribution. Stockout probability in 14 days is 78%.
With this three-week window, the inventory team has options. They can expedite the existing order with the supplier, potentially paying a premium for faster shipping. They can place a smaller bridge order with an alternative supplier who has shorter lead times. They can reduce marketing spend on the product to slow demand while maintaining organic sales. They can set up a back-in-stock notification to capture demand during any stockout period.
Without the early warning, none of these mitigation options are available. By the time a human notices the inventory is low through manual checks, the lead time has already eaten into the remaining stock.
Building the Model
The technical implementation uses a combination of time-series forecasting for demand (typically Prophet or a custom LSTM model) and a classification model for stockout probability. The classification model takes the demand forecast, current inventory position, and supplier lead time distribution as inputs and outputs a probability of stockout within each time window.
Training data comes from your historical inventory records. Every past stockout is a positive example, and every SKU that maintained adequate stock through a given period is a negative example. You need at least 12-18 months of daily inventory snapshots with corresponding sales data to train a useful model. If you have not been storing daily inventory levels, start now because this data is surprisingly hard to reconstruct retroactively.
Feature engineering is where most of the value is created. Raw sales numbers are less useful than derived features like 7-day rolling average velocity, week-over-week velocity change, coefficient of variation in daily sales (a measure of demand volatility), and ratio of current velocity to the 90-day average. These derived features help the model distinguish between a steady seller approaching its reorder point and a product experiencing a demand spike that will burn through inventory much faster than expected.
Integration With Existing Systems
The model needs to plug into your inventory management workflow, not replace it. The most common approach is a daily alert dashboard that shows SKUs ranked by stockout risk, with recommended actions for each. Inventory planners review the dashboard each morning and take action on high-risk items.
More advanced implementations automate the response for low-risk actions. If the model predicts a stockout and the recommended action is to place a standard reorder with an existing supplier, the system can generate the purchase order automatically and queue it for one-click approval by the inventory manager. This keeps a human in the loop for the decision while eliminating the manual work of creating the order.
For ecommerce retailers running thousands of SKUs, manual inventory monitoring simply cannot scale. A human checking 3,500 SKUs per day will inevitably miss the ones that are quietly accelerating toward a stockout. The ML model checks every SKU every hour, catches the subtle patterns, and surfaces the ones that need attention. The beauty retailer that started this conversation cut their stockout rate from 8-12% to under 3% within six months of deploying their prediction model, which translated to roughly $940,000 in recovered annual revenue.