Prescriptive Analytics in Python: Explanation with Supply Chain Optimization Example
- Samul Black

- Jan 7, 2024
- 7 min read
Updated: Jul 22
Data analytics and prescriptive analytics: Empowering Optimal Decisions with Data-Driven Precision. Unlocking Strategies for Success through Prescriptive Analytics. A walk through what prescriptive analytics is, its applications, features and future prospect.

What is Prescriptive Analytics?
Prescriptive analytics represents the pinnacle of data-driven decision-making, offering more than just predictions about future outcomes. It's the realm where data, algorithms, and business objectives converge to provide actionable insights and recommended courses of action. Unlike descriptive or predictive analytics, which focus on understanding past events or forecasting future trends, prescriptive analytics harnesses the power of advanced technologies and mathematical models to suggest the best possible actions to achieve specific outcomes. It assesses multiple scenarios, evaluates potential actions, and guides decision-makers towards the most favorable paths by optimizing resources, mitigating risks, and maximizing opportunities. This transformative approach empowers organizations across industries to make smarter, informed decisions in an increasingly complex and dynamic business environment.
Features of Prescriptive Analytics
Prescriptive analytics, the advanced stage of analytics, possesses several distinctive features some of which are quite similar to predictive analytics, but collectively stand aloof from it. Here are the key features of prescriptive analytics in detail:
Actionable Insights
Prescriptive analytics doesn't stop at providing insights or predictions; it goes further by offering actionable recommendations. It suggests specific actions or decisions to optimize outcomes based on data-driven insights. These recommendations guide decision-makers on the best course of action to achieve desired objectives.
Optimization and Decision Support
One of the primary goals of prescriptive analytics is optimization. It helps in optimizing decisions by evaluating various scenarios and identifying the most effective choices. This involves considering multiple constraints, objectives, and potential outcomes to recommend the best decision or strategy.
What-If Analysis and Scenario Planning
Prescriptive analytics enables what-if analysis and scenario planning by exploring different hypothetical situations. It allows decision-makers to simulate various scenarios and assess the potential outcomes before making critical decisions. This helps in understanding the implications of different choices and their impact on desired goals.
Dynamic and Real-Time Decision Making
Prescriptive analytics operates in real-time or near real-time, providing dynamic recommendations that can adapt to changing conditions. It enables organizations to make informed decisions promptly as new data becomes available, allowing for agile responses to evolving situations.
Integrative Approach and Cross-Functional Insights
Prescriptive analytics takes an integrative approach, combining data from multiple sources and departments within an organization. By analyzing diverse data sets, it generates cross-functional insights that offer a comprehensive view of operations, allowing for holistic decision-making.
Machine Learning and AI-Powered Algorithms
The use of machine learning algorithms and artificial intelligence (AI) is prevalent in prescriptive analytics. These advanced algorithms continuously learn from data patterns, improve over time, and offer more accurate and personalized recommendations.
Dynamic Optimization and Adaptive Strategies
Prescriptive analytics models adapt and optimize strategies dynamically. They continuously learn from new data inputs and adjust recommendations, strategies, or action plans to align with changing circumstances, ensuring ongoing optimization and performance improvement.
Consideration of Constraints and Trade-Offs
Prescriptive analytics considers various constraints, trade-offs, and objectives when recommending actions. It evaluates the feasibility of decisions within the constraints of resources, budgets, regulations, and other limitations while balancing conflicting objectives.
Ethical and Explainable Recommendations
Ethical considerations are integral to prescriptive analytics. Transparent and explainable recommendations ensure that the decision-making process is fair, unbiased, and accountable. There's a focus on ensuring that the recommendations align with ethical guidelines and regulatory compliance.
These key features collectively empower organizations to make informed, optimal decisions, driving efficiency, innovation, and competitive advantage across various industries and domains.
Applications of Prescriptive Analytics
Prescriptive analytics finds applications across various industries, revolutionizing decision-making processes by providing actionable insights and recommendations. Here are detailed applications of prescriptive analytics:
Supply Chain Optimization
Prescriptive analytics plays a crucial role in optimizing supply chain operations. It assists in inventory management by recommending optimal stock levels, predicting demand fluctuations, and identifying the most efficient distribution networks. By analyzing historical data and considering various constraints (such as transportation costs, storage capacities, and lead times), prescriptive analytics helps organizations streamline logistics, reduce costs, and ensure timely delivery of goods.
Healthcare Decision Support
In the healthcare sector, prescriptive analytics aids in clinical decision-making and personalized treatments. By analyzing patient data, medical histories, and clinical outcomes, it assists healthcare professionals in determining the most effective treatment plans. It helps in identifying potential risks, suggesting suitable interventions, optimizing hospital resource allocation, and improving patient outcomes.
Financial Planning and Risk Management
Financial institutions use prescriptive analytics to manage risks, optimize investments, and improve financial planning. It helps in predicting market trends, identifying potential risks in portfolios, and suggesting strategies for risk mitigation. Prescriptive analytics models assess various investment scenarios, optimize asset allocation, and provide recommendations for maximizing returns while minimizing risks.
Marketing Campaign Optimization
Prescriptive analytics aids marketing professionals in optimizing their campaigns and strategies. By analyzing customer behavior, preferences, and purchasing patterns, it recommends personalized marketing approaches. It helps in segmenting customers, identifying target audiences, determining the most effective channels, and optimizing promotional offers to enhance customer engagement and maximize ROI.
Energy and Utilities Management
In the energy sector, prescriptive analytics assists in optimizing resource usage, predicting energy demand, and improving operational efficiency. It helps in optimizing energy distribution, scheduling maintenance, predicting equipment failures, and recommending optimal utilization of resources. This aids in minimizing downtime, reducing costs, and ensuring a more reliable energy supply.
Human Resources and Workforce Management
Prescriptive analytics is utilized in HR to optimize workforce planning, talent acquisition, and employee management. By analyzing employee data, performance metrics, and workforce trends, it assists in identifying skill gaps, optimizing staffing levels, and suggesting strategies for talent retention and succession planning.
These applications showcase the versatility and impact of prescriptive analytics across industries, driving smarter decisions, optimizing processes, and fostering innovation by leveraging data-driven insights and recommendations.
Prescriptive Analytics for Supply Chain Optimization in Python
Prescriptive analytics is the final frontier in data-driven decision-making. After descriptive and predictive analytics tell you what happened and what is likely to happen, prescriptive analytics tells you what to do about it. In this example, we’ll explore how to optimize a supply chain using Python and linear programming, solving real business problems like minimizing transportation costs while meeting customer demand and warehouse constraints.
We’ll use the PuLP library in Python to create and solve this optimization model.
Scenario: Minimizing Transportation Costs in a Supply Chain
Imagine you're managing logistics for a company that ships goods from two warehouses to three retail stores. Each warehouse has a limited supply of inventory, and each store requires a certain amount of goods. Transportation costs vary depending on the route. Your goal is to minimize the total cost of shipping while ensuring all store demands are met and warehouse supply constraints are respected.
Step 1: Install and Import Required Libraries
We start by installing PuLP, a powerful linear programming toolkit in Python. It's designed to help us define optimization problems and solve them with solvers like CBC.
!pip install pulp
import pulpStep 2: Define the Data for the Problem
This is where we define the business landscape:
Two warehouses with limited stock.
Three stores, each needing a fixed number of units.
A transportation cost grid telling us the price to ship goods from each warehouse to each store.
This setup mirrors real-world logistics, where managing routes, costs, and inventory is crucial.
# 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,
}Step 3: Define the Optimization Problem
We now define our objective—we want to minimize transportation costs. This tells PuLP we’re setting up a minimization problem.
# Create the LP problem
model = pulp.LpProblem("Minimize_Transportation_Costs", pulp.LpMinimize)Step 4: Define Decision Variables
These variables represent how much to ship from each warehouse to each store. For example, Route[Warehouse_1][Store_A] will hold the number of units shipped along that specific route.
We constrain it to be non-negative integers because you can’t ship a negative number of units or fractional products.
# Create decision variables for shipment quantities
routes = pulp.LpVariable.dicts("Route", (warehouses, stores), lowBound=0, cat='Integer')Step 5: Define the Objective Function (Minimize Total Cost)
This line calculates total transportation cost across all routes, by multiplying the units shipped with their per-unit cost and summing across all paths. This is what we’re trying to minimize.
# Objective function: total cost
model += pulp.lpSum([routes[w][s] * costs[(w, s)] for w in warehouses for s in stores]), "Total_Transportation_Cost"Step 6: Add Constraints
Now we lock down real-world limitations:
Each warehouse can’t ship more than what it has in stock.
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}"Step 7: Solve the Optimization Problem
This runs the model through an optimization solver. PuLP uses the default CBC solver to find the best shipping plan that minimizes cost while respecting supply and demand.
# Solve the model
model.solve()Step 8: Print the Results
This is the payoff. We print the optimal shipping plan showing exactly how many units to send from each warehouse to each store. It also displays the minimum total 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.00This prescriptive analytics example shows how optimization algorithms in Python can guide logistics managers to make data-backed, cost-effective decisions. Instead of guessing how to allocate inventory, the model delivers the most economical plan while ensuring everyone gets what they need.
Conclusion: From Insight to Action with Prescriptive Analytics
Prescriptive analytics is the strategic edge businesses need in today’s data-driven world. While descriptive analytics tells you what has happened, and predictive analytics forecasts what’s likely to happen, prescriptive analytics empowers you to make optimal decisions on what to do next.
In this blog, we explored the core features of prescriptive analytics—optimization, simulation, and real-time decision-making—and walked through its applications across industries, from healthcare to finance and logistics.
The Python-based supply chain optimization example brought these concepts to life. Using linear programming with PuLP, we built a model that minimizes shipping costs while satisfying real-world constraints—showcasing how prescriptive analytics moves beyond reporting to actual strategic execution.




