Using Machine Learning to Smartly Stock Grocery Stores

Professor Kevin Shang has developed a machine-learning solution to allow grocers to stock optimal amounts of perishable food in their supply chains

September 6, 2023
Big Data, Operations
Kevin Shang_Machine Learning & Grocery's Supplies_Duke University's Fuqua School of Business

Consider the unassuming Chinese cabbage. Low in calories yet rich in nutrients, it’s a staple on dinner tables around China, but when Chinese grocery stores stock too much of it as well as other highly perishable fruits and vegetables, already razor-thin profit margins take a hit.  

Thanks to a new data-driven replenishment and allocation policy developed by Duke Fuqua School of Business professor Kevin Shang, the fast-growing grocery chain Fresh Hema, a subsidiary of internet retail giant Alibaba, may soon see an almost 11% cost savings for this item, a finding that could mean similar savings for other stock-keeping-units that must be swiftly sold or thrown away.

Shang is co-author of “Taylor Approximation of Inventory Policies for One-Warehouse, Multi-Retailer Systems with Demand Feature Information” which will be published in the journal Management Science. He and his co-authors at Zhejiang University built an innovative machine-learning algorithm for Fresh Hema based on six months of its daily inventory sales and other factors such as weather, shopper demographics, income, genders, age, seasonal variations, and unique characteristics of its stores in Chengdu, a city of 20 million in southern China.

“We developed an inventory solution that can leverage the most up-to-date factors that impact the demand and give a fast computation so the company can allocate the right amount of inventory to each retail store according to the most recent information,” Shang said.

The need for a fast machine-learning algorithm

Thanks to a native cuisine that has historically placed a premium on freshness, Chinese consumers demand straight-from-the-farm food more than Americans do. Shang says China’s grocery market is very much like those in Western nations where chains fight for thin profits in the face of slow-growing sales.

Fresh Hema’s 16 retail stores in Chengdu are serviced by one central warehouse. Every morning the central warehouse observes data from the stores to estimate the demand and places orders for produce, meat, and eggs from nearby farmers. Shortly after midnight, the merchandise arrives and undergoes cross-docking, swiftly getting loaded onto outbound trucks destined for retail store delivery. By 6 a.m. the next day, they are already shelved and ready for customers. In short, Hema’s current practice uses “day-before” information for inventory replenishment.

“Hema’s current practice is inefficient,” Shang said. “It will be very ideal if at the moment you receive the material at the warehouse, you have a fast algorithm to leverage the most immediately available information. Then you can quickly relocate inventory for shipment to diverse retail outlets with different needs. This is using real-time information for inventory replenishment.”

“This is the challenge that we aim to tackle,” Shang said. “We need an algorithm that can solve the allocation decision for more than 400 stock-keeping units after observing the same-day feature information in less than an hour to meet the 6 a.m. target.”

“There’s a significant difference between managing one location and many locations,” Shang said. “If your warehouse supplies only one store, you just order what you need, but here we’re talking about a distribution supply chain. What one store orders is going to impact the others. It’s a very complicated system to juggle with high efficiency.”

A two-step approach

Shang and his colleagues are among the first in inventory management research to address the “one-warehouse-multi-retailer” problem by leveraging the most up-to-date factors that impact the demand. They developed an algorithm that utilizes the same-day information and generates solutions using a two-step process.

The first step involves solving the inventory allocation decision among retailer stores through a mathematical method known as a Taylor Series or Taylor Expansion. Named after 18th-century English mathematician Brook Taylor, it has long given scientists, engineers, and astronomers solutions for fantastically complex problems such as calculating the orbit of Halley’s Comet.

“Suppose you have 100 units of something and 16 stores as Hema does in Chengdu, each store has a different lead time, different cost structures, and different factors that impact customer demand,” Shang said. “How do you best allocate those 100 units in a real-time fashion? That’s a complicated problem, which people refer to as the ’curse of dimensionality.’ There is no causal solution. In our algorithm, we get a fast computation of an ideal solution, and its elegance arises from a Taylor Expansion.”

After running the Taylor Expansion, Shang and his co-authors then applied machine learning algorithms using current demand information for the final solution, Data-Driven Taylor Approximation (DDTA).

“The final result is the data-driven solution, because all of its probability components come from real data, and statistical tools have refined them in the final analysis,” Shang said.

In contrast to Hema’s policy based on day-before information, Shang’s data-driven algorithm more precisely predicted demand in a far more real-time manner, something that would have been impossible in the past.

The larger impact of reducing food waste

Shang’s research represents a promising step toward ending the massive problem of worldwide food waste. Not only is it one of the biggest bottom-line headaches faced by groceries, 40 percent of food produced never gets eaten, according to the Worldwide Wildlife Fund.           

The Food Waste Reduction Alliance, which is composed of the Food Industry Association, the Consumer Brands Association, and the National Restaurant Association, supports the U.S. government’s goal to cut food waste by 50 percent by 2030. The Zero Waste Food Act, which was proposed in Congress in 2022, calls for the creation of a new federal agency to cut food waste.

“I don’t want to overstate our findings in this paper,” Shang said. “But we kept the big picture in mind. Reducing food waste is a big problem everywhere, and if companies can better match demand with supply, food waste will be substantially reduced, supply chain costs will be cut, companies’ bottom lines will get a boost, and, last but not least, shoppers will find what they’re looking for on store shelves. It’s a win-win for everyone.”

This story may not be republished without permission from Duke University's Fuqua School of Business. Please contact for additional information.

Contact Info

For more information contact our media relations team at