Niklas Tscheuschner - Data Science Semesterprojekt

Optimizing Pharmacy Inventories

The market for prescription medicine is becoming increasingly competitive. Online pharmacies attract customers with low prices and high drug availability – enabled through centralized storages and data driven stocking systems. Retail pharmacies on the other hand, rely on their edge in consulting and service. Technologies in Big Data or Machine Learning are, however, not exclusive to large businesses.

In this project, the in-store inventory of a retail pharmacy was optimized for drug availability. Scenarios in which a customer’s prescription cannot be immediately served not only pose a danger to the individual’s health but also to the economics of the pharmacy. Supply through a wholesaler results in long wait times and inconvenient roundtrips for the customer. Additionally, the pharmacy loses on profit since patients might take their prescription to the competition or switch to mail order.

In cooperation with a Halle-based retail pharmacy (opened in 1993, nine employees), the stated problem was addressed by handing inventory control over to a reinforcement learning agent. Through rewards and penalties, the agent learned which drugs should be kept in stock and which are suitable for on-demand ordering from the wholesale. The rewards were defined on the basis of a dataset which contains successful and dismissed transactions collected in the pharmacy from 2004 to 2021.

Using a deep neural network as decision policy together with a variation of the popular Q-learning algorithm, the agent initially failed to outperform the manually managed inventory. The assignment of credits to the agent’s actions turned out to be especially challenging since rewards arrive only time-delayed. Still, when comparing the stocking strategy of the agent with snapshots of the manually managed inventory, it is noticeable that the agent adapts to seasonality faster and takes advantage of the available storage capacities more efficient.