Beyond ML Loss Function: Cost Functions and Hypothesis Testing in Supply Chain
Last Updated on September 29, 2025 by Editorial Team
Author(s): Siddharth Mahato
Originally published on Towards AI.
Understand how Cost Functions and Statistics can help you go beyond accuracy with visuals and examples.

Manufacturing is a large and crucial part of the economy. It involves processing and refining raw materials like ore, wood, and food into finished products such as metal goods, furniture, and processed foods. Transforming raw materials into useful products adds value and increases their selling price, making manufacturing profitable. Some people focus on the skills needed to manufacture goods, while others supply the funds businesses require to acquire tools and materials.
This article explores how mathematical cost functions drive billion-dollar decisions in manufacturing and supply chains. Through a practical case study using real supply chain data, we’ll demonstrate how shifting from technical optimization to economic intelligence can transform your operational decisions. We’ll bridge the gap between statistical hypothesis testing and business outcomes, providing a framework that connects machine learning predictions to tangible profitability.
┌──────────────────┐
ML Loss Functions
└─────────┬────────┘
Optimizes ↓
┌─────────┴──────────┐
Predictive Accuracy
└─────────┬──────────┘
Transforms via ↓
┌─────────┴──────────┐
Economic Cost
Functions
└─────────┬──────────┘
Drives ↓
┌─────────┴──────────┐
Business Profit
└─────────┬──────────┘
Applied to ↓
┌─────────┴──────────┐
Supply Chain Opt
└─────────┬──────────┘
Generates ↓
┌─────────┴──────────┐
$ Impact
└────────────────────┘
Problem Setup
1. The Dataset: Supply Chain at Scale
We’ll be using a publicly available Kaggle dataset with 180,000+ rows and 53 columns, covering multiple aspects of the supply chain:
- Product categories (Cosmetics, Clothing, Household, etc.)
- Price, Revenue generated, Net profit
- Manufacturing and Transportation costs
- Competitor prices & Customer demographics
For our case study, we’ll focus on these three key columns:
> Manufacturing costs
> Price
> Revenue generated
2. Data Cleaning & Preparation
Code:
import pandas as pd
# Load dataset
df = pd.read_excel("supply_chain_data.csv.xlsx")
# Select relevant columns
data = df[["Product type", "Price", "Manufacturing costs", "Revenue generated"]].dropna()
# Quick look
data.head()

The Cost Function: Economic Reality vs. ML Optimization
At its core, every cost function answers one question: “How much does this decision cost us?” But the definition of “cost” varies dramatically between disciplines.
Economics: Cost as Business Reality
# What does it actually cost to make things?
def manufacturing_cost(units_produced, raw_material_costs, labor_costs):
"""Calculates the real financial cost of production"""
return (fixed_costs + raw_material_costs * units_produced + labor_costs * units_produced)
Economic cost functions measure tangible business impacts — dollars spent, resources consumed, opportunities missed.
Machine Learning: Cost as Prediction Error
# How wrong are our predictions?
def prediction_cost(actual_values, predicted_values):
"""Quantifies the accuracy of our models"""
return np.sum((actual_values - predicted_values) ** 2)
ML cost functions measure abstract errors — the gap between predicted and actual outcomes.
The Universal Role: Cost Function as Judge
Whether in economics or machine learning, the cost function serves as an objective judge:
- In economics: It evaluates production efficiency and profitability
- In machine learning: It evaluates prediction accuracy and model performance
- In both cases: It provides the optimization target for decision-making
However, our main goal is to analyze the cost function for logistics.

3. Building a Cost Function
import statsmodels.api as sm
X = data["Manufacturing costs"]
y = data["Revenue generated"]
X = sm.add_constant(X) # adding intercept
model = sm.OLS(y, X).fit()
print(model.summary())

This regression shows how much revenue changes with each unit increase in manufacturing costs.
Key Insights from the OLS Results:
I) The Economic Relationship is Real (but Complex)
- P-value for Manufacturing Costs: 0.033 (< 0.05) → Statistically significant
- Coefficient: -20.18 → Each $1 increase in manufacturing costs associates with $20.18 decrease in revenue
- This suggests inefficiencies: Higher costs don’t translate to higher revenue
II) The Model Has Limitations
- R-squared: 0.046 → Only 4.6% of revenue variation explained by manufacturing costs alone
- This confirms: We need a multi-dimensional cost function, not just single-variable optimization
III) Business Interpretation
Baseline Performance: Companies with optimized manufacturing processes generate approximately $6,730 in baseline revenue without considering cost inefficiencies-
- Cost Efficiency Crisis: Each additional dollar spent on manufacturing correlates with $20.18 less revenue, indicating serious operational inefficiencies or misallocated resources.
- Strategic Implication: Simply cutting costs isn’t the solution — the negative relationship suggests poor cost management rather than excessive spending. Companies may be investing in non-value-adding activities.
- Missing Variables Alert: With only 4.6% of revenue variation explained by manufacturing costs alone, we’re missing critical factors like product quality, market demand, and competitive positioning
- Management Decision Point: The analysis reveals that cost optimization requires contextual understanding — blind cost reduction could worsen the negative revenue relationship if underlying inefficiencies aren’t addressed.
4. Visualizing Cost vs Revenue
# Visualization
plt.scatter(data["Manufacturing costs"], data["Revenue generated"], alpha=0.5)
plt.xlabel("Manufacturing Costs ($)")
plt.ylabel("Revenue Generated ($)")
plt.title("Cost vs Revenue in Supply Chain")
plt.show()

This scatterplot makes it clear whether higher costs actually lead to higher revenue.
5. Hypothesis Testing: Do Higher Costs Actually Pay Off?
Now, let’s test a business hypothesis:
- Null Hypothesis (H₀): Average manufacturing cost = $250 (industry benchmark)
- Alternative Hypothesis (H₁): Average manufacturing cost > $250
from scipy import stats
sample = data["Manufacturing costs"].sample(50, random_state = 42)
t_stat, p_val = stats.ttest_1samp(sample, 250)
print("t-statistic:", t_stat)
print("p-value:", p_val)

The results are extremely statistically significant.
Business Interpretation & Strategic Insights:
Dramatic Cost Advantage: Your manufacturing costs are significantly lower than the $250 industry benchmark — this isn’t a minor edge, but a substantial competitive moat.
- Pivot from Cost-Cutting to Growth: Traditional “reduce costs” advice doesn’t apply here. Instead, focus on monetizing this efficiency through market expansion or premium positioning.
- Investigate the “Why”: Such extreme cost advantages could indicate either breakthrough operational efficiency or potential quality compromises that need validation.
- Revenue Optimization Priority: With costs already optimized, your economic cost function should prioritize revenue maximization rather than further cost reduction.
- Strategic Imperative: This cost advantage represents a foundation for aggressive growth — the question shifts from “how to cut costs” to “how to leverage this advantage for maximum market impact”
Conclusion
This hypothesis test changes our approach. Instead of creating cost functions based on efficiency improvements, we need economic cost functions that turn existing cost advantages into market dominance.
Why it Matters:
Cost optimization is the heartbeat of supply chains.
- If costs rise without increasing revenue, profits shrink.
- If higher costs do lead to higher revenue, the investment is justified.
- Hypothesis testing helps managers move from “gut feelings” to data-driven decisions.
Dataset
The Supply Chain dataset used in this article is from kaggle, which is licensed under CCO (Public Domain), making it safe for use in this analysis and publication.
I hope you enjoyed reading this article.
Feel free to share your thoughts.
Thanks for reading!
Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.
Published via Towards AI
Take our 90+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!
Towards AI has published Building LLMs for Production—our 470+ page guide to mastering LLMs with practical projects and expert insights!

Discover Your Dream AI Career at Towards AI Jobs
Towards AI has built a jobs board tailored specifically to Machine Learning and Data Science Jobs and Skills. Our software searches for live AI jobs each hour, labels and categorises them and makes them easily searchable. Explore over 40,000 live jobs today with Towards AI Jobs!
Note: Content contains the views of the contributing authors and not Towards AI.