Prescriptive Analytics in Python: Explanation with Supply Chain Optimization Example
- Jan 7, 2024
- 8 min read
Updated: Mar 10
Data analytics has evolved far beyond simple reporting. While descriptive analytics explains what has happened and predictive analytics estimates what might happen in the future, prescriptive analytics focuses on recommending the best possible actions based on available data.
Prescriptive analytics combines optimization techniques, mathematical modeling, and machine learning to help organizations make better decisions under constraints. Instead of just forecasting demand or identifying trends, it determines the optimal strategy to achieve a specific goal such as minimizing cost, maximizing profit, or improving operational efficiency.
In this guide, we explore the fundamentals of prescriptive analytics and demonstrate how it can be implemented using Python. Using the PuLP optimization library, we will build a practical supply chain optimization model that determines the most cost-efficient way to distribute products from warehouses to retail stores while satisfying supply and demand constraints.

What is Prescriptive Analytics?
Prescriptive analytics represents the most advanced stage of data analytics, focusing on recommending the best possible actions based on data. While descriptive analytics explains what has already happened and predictive analytics estimates future outcomes, prescriptive analytics goes one step further by suggesting optimal decisions that help achieve specific business goals.
This approach combines optimization techniques, statistical modeling, and machine learning algorithms to evaluate multiple scenarios and determine the most effective strategy. By analyzing historical data, operational constraints, and potential outcomes, prescriptive analytics identifies the decisions that maximize efficiency, reduce risk, or improve performance.
Organizations increasingly rely on prescriptive analytics to solve complex decision-making problems. From supply chain planning and resource allocation to pricing strategies and logistics optimization, prescriptive models help businesses transform raw data into clear, actionable recommendations that guide real-world operations.
Features of Prescriptive Analytics
Prescriptive analytics goes beyond reporting trends or predicting outcomes by recommending specific actions. Instead of stopping at insights, it translates analytical results into practical decisions that help organizations improve efficiency, reduce costs, and achieve business objectives.
A core capability of prescriptive analytics is optimization. Advanced mathematical and machine learning models evaluate multiple decision options and determine the strategy that produces the best possible outcome. These models support decision-making by balancing objectives such as maximizing profits, improving operational performance, or minimizing risk.
Another powerful feature is scenario analysis. Prescriptive analytics allows organizations to perform what-if simulations and test different strategies before implementing them in real-world operations. By exploring multiple scenarios, decision-makers can understand potential risks and select strategies that deliver the most favorable results.
Modern prescriptive analytics systems also support dynamic decision-making. As new data becomes available, models update recommendations in near real time, allowing organizations to quickly adapt to market changes, supply disruptions, or shifting customer demand.
These systems typically integrate data from multiple sources across an organization. By combining operational, financial, and external datasets, prescriptive analytics provides a comprehensive perspective that improves cross-functional decision-making.
Machine learning and AI technologies further enhance these models by identifying patterns in large datasets and continuously improving recommendation accuracy. At the same time, prescriptive analytics accounts for real-world constraints such as budgets, capacity limits, and regulations, ensuring that recommended actions remain practical and achievable.
Finally, modern prescriptive analytics emphasizes transparency and explainability. Organizations need to understand how recommendations are generated so decision-makers can trust the models and ensure responsible, compliant use of data-driven strategies.
Applications of Prescriptive Analytics
Prescriptive analytics goes beyond traditional analytics by recommending specific actions instead of simply reporting insights or predicting future trends. It combines advanced algorithms, optimization models, and business rules to determine the best possible decisions in complex situations. Organizations rely on prescriptive analytics to improve operational efficiency, allocate resources effectively, and make smarter strategic decisions.
Some key capabilities that define prescriptive analytics include:
Actionable recommendations: Instead of only presenting insights, prescriptive analytics suggests concrete actions that improve outcomes.
Optimization-driven decisions: Mathematical models evaluate multiple decision options and identify strategies that maximize efficiency, minimize cost, or improve performance.
What-if scenario analysis: Organizations can simulate different situations and evaluate possible outcomes before implementing decisions.
Real-time decision support: Modern systems update recommendations dynamically as new data becomes available.
Integrated data analysis: Data from multiple departments and sources is combined to provide a complete operational perspective.
AI and machine learning models: These technologies continuously learn from data and improve the accuracy of recommendations over time.
Constraint-aware optimization: Models consider real-world limitations such as budgets, capacity, and regulatory requirements.
Together, these capabilities allow organizations to move from simple data analysis to intelligent decision-making. By evaluating multiple scenarios and balancing operational constraints, prescriptive analytics helps businesses identify strategies that deliver optimal outcomes while adapting to constantly changing environments.
Implementing Prescriptive Analytics for Supply Chain Optimization in Python
Prescriptive analytics represents the final stage of data-driven decision making. Descriptive analytics explains past performance, predictive analytics estimates future outcomes, and prescriptive analytics determines the best actions to take next. Instead of stopping at insights or forecasts, prescriptive models evaluate multiple decision paths and recommend the most efficient strategy.
In this example, we will build a simple supply chain optimization model in Python. The goal is to minimize transportation costs while satisfying customer demand and respecting warehouse capacity limits. To achieve this, we will use linear programming, a mathematical optimization technique commonly used in logistics, operations management, and resource planning.
Python provides several libraries for optimization tasks, and in this guide we will use PuLP, a lightweight linear programming toolkit that allows us to define decision variables, constraints, and objective functions in a clear and intuitive way.
Scenario: Minimizing Transportation Costs in a Supply Chain
Imagine you are managing logistics for a company that ships products from two warehouses to three retail stores. Each warehouse contains a limited inventory supply, while each store requires a fixed quantity of goods to meet customer demand. Shipping costs vary depending on the route taken from a warehouse to a store.
Your objective is straightforward: determine the optimal shipping plan that delivers the required goods to every store while minimizing the total transportation cost.
To solve this optimization problem, the model must consider three main factors:
Warehouse supply limits that restrict how many units each warehouse can ship
Store demand requirements that must be satisfied for all retail locations
Transportation costs associated with shipping goods between warehouses and stores
The optimization algorithm will evaluate possible shipping combinations and identify the solution that meets all constraints while producing the lowest total cost.
Step 1: Install and Import Required Libraries
We begin by installing PuLP, which allows us to define and solve linear programming problems directly in Python. PuLP includes built-in solvers that automatically compute optimal solutions once the model is defined.
!pip install pulp
import pulpStep 2: Define the Data for the Problem
Next, we define the core elements of the supply chain. These include the available warehouses, their inventory capacity, the stores that require goods, and the transportation cost associated with each shipping route.
This data represents the business environment our optimization model will operate within.
# Warehouses and their supply capacity
warehouses = ['Warehouse_1', 'Warehouse_2']
supply = {'Warehouse_1': 100, 'Warehouse_2': 150}
# Stores and their demand
stores = ['Store_A', 'Store_B', 'Store_C']
demand = {'Store_A': 80, 'Store_B': 90, 'Store_C': 70}
# Cost matrix (cost per unit from each warehouse to each store)
costs = {
('Warehouse_1', 'Store_A'): 2,
('Warehouse_1', 'Store_B'): 4,
('Warehouse_1', 'Store_C'): 5,
('Warehouse_2', 'Store_A'): 3,
('Warehouse_2', 'Store_B'): 1,
('Warehouse_2', 'Store_C'): 7,
}In real-world logistics systems, this type of data would typically come from enterprise databases, inventory systems, or demand forecasting models. Once these variables are defined, the next step is to construct the optimization model, where we create decision variables, define constraints, and specify the objective function that minimizes transportation costs.
Step 3: Define the Optimization Problem
Next, we create the optimization model. In this case, our goal is to minimize the total transportation cost across all warehouse–store routes. Linear programming models require defining the objective type first, which tells the solver if it should minimize or maximize the final value.
Since our objective is cost reduction, we define a minimization problem using PuLP.
# Create the LP problem
model = pulp.LpProblem("Minimize_Transportation_Costs", pulp.LpMinimize)Step 4: Define Decision Variables
Decision variables represent the values the optimization model must determine. In this case, they represent how many units should be shipped from each warehouse to each store.
For example, Route[Warehouse_1][Store_A] represents the quantity shipped from Warehouse 1 to Store A. These variables are constrained to be non-negative integers, since shipments cannot be negative and individual units typically cannot be fractional in logistics problems.
# Create decision variables for shipment quantities
routes = pulp.LpVariable.dicts("Route", (warehouses, stores), lowBound=0, cat='Integer')This creates a grid of variables for every possible warehouse–store combination, allowing the optimization model to determine the most efficient shipping plan.
Step 5: Define the Objective Function (Minimize Total Cost)
The objective function defines what the optimization model is trying to achieve. In this scenario, we want to minimize the total transportation cost across all shipping routes.
The cost is calculated by multiplying the number of units shipped along each route by its corresponding transportation cost, and then summing the costs across all warehouse–store combinations.
# Objective function: total cost
model += pulp.lpSum([routes[w][s] * costs[(w, s)] for w in warehouses for s in stores]), "Total_Transportation_Cost"Once the objective function is defined, the next step is to add constraints that ensure warehouse supply limits and store demand requirements are respected. These constraints guide the optimization solver toward solutions that are both efficient and feasible within the supply chain system.
Step 6: Add Constraints
Optimization models must reflect real-world limitations. In a supply chain environment, warehouses cannot ship more goods than they have available, and stores must receive the quantities required to meet demand.
These restrictions are expressed through constraints, which ensure that the optimization solver produces solutions that are practical and feasible.
First each warehouse can’t ship more than what it has in stock.Second each store must receive at least the number of units it needs.
These constraints keep the solution feasible and realistic, just like in a real supply chain.
# Supply constraints for warehouses
for w in warehouses:
model += pulp.lpSum([routes[w][s] for s in stores]) <= supply[w], f"Supply_Constraint_{w}"
# Demand constraints for stores
for s in stores:
model += pulp.lpSum([routes[w][s] for w in warehouses]) >= demand[s], f"Demand_Constraint_{s}"With these constraints in place, the solver will only consider shipment plans that satisfy both supply availability and store demand.
Step 7: Solve the Optimization Problem
Once the objective function and constraints are defined, the model can be solved using PuLP’s built-in optimization solver. By default, PuLP uses the CBC solver, which evaluates possible shipping combinations and determines the plan that minimizes total transportation cost.
# Solve the model
model.solve()The solver automatically analyzes the decision variables, objective function, and constraints to compute the optimal shipping strategy.
Step 8: Print the Results
After the optimization process completes, we can display the results. The following code prints the model status, the optimal shipment plan, and the minimum transportation cost.
# Output results
print(f"Status: {pulp.LpStatus[model.status]}")
print("Optimal Shipment Plan:")
for w in warehouses:
for s in stores:
print(f"Ship {routes[w][s].varValue} units from {w} to {s}")
print(f"Total Minimum Cost: ${pulp.value(model.objective):.2f}")
Output:
Status: Optimal
Optimal Shipment Plan:
Ship 30.0 units from Warehouse_1 to Store_A
Ship 0.0 units from Warehouse_1 to Store_B
Ship 70.0 units from Warehouse_1 to Store_C
Ship 50.0 units from Warehouse_2 to Store_A
Ship 90.0 units from Warehouse_2 to Store_B
Ship 0.0 units from Warehouse_2 to Store_C
Total Minimum Cost: $650.00The results show the optimal number of units that should be shipped from each warehouse to each store. By evaluating all possible shipment combinations, the optimization model identifies the plan that satisfies demand while minimizing transportation costs.
This simple example demonstrates how prescriptive analytics with Python can guide logistics decisions. Instead of manually estimating shipment allocations, optimization algorithms compute the most cost-efficient strategy while respecting operational constraints, helping organizations improve supply chain efficiency through data-driven decision-making.
Conclusion
In modern data-driven environments, the ability to predict outcomes is no longer enough. Organizations increasingly need systems that can recommend the most effective actions when faced with operational constraints, competing objectives, and rapidly changing conditions. Prescriptive analytics fills this gap by combining mathematical optimization, data modeling, and business logic to guide real-world decisions.
Supply chain management is one of the areas where this capability delivers immediate value. Transportation routes, inventory availability, and demand requirements create complex decision spaces that are difficult to manage through manual planning alone. Optimization models built with Python allow these challenges to be translated into structured problems where algorithms evaluate thousands of possible scenarios and identify the most cost-efficient strategy.





