We Are Not Astrologers, We Are Machine Learning Scientists
Why Predicting a Number Is Easy, but Predicting Uncertainty Is Science
Imagine you visit an astrologer.
You ask:
“Will I get a promotion next year?”
The astrologer closes their eyes and says:
“Yes. Absolutely.”
No explanation.
No confidence interval.
No uncertainty.
Just one number.
Surprisingly, most machine learning models behave exactly like this.
The Problem with Traditional Neural Networks
Suppose we want to predict house prices.
Inputs:
- Area = 2000 sq ft
- Bedrooms = 3
- Age = 10 years
Output:
- House Price
A traditional neural network learns a function:
Price = f(X)
After training, it might predict:
Predicted Price = $500,000Sounds good.
But should we trust it?
What if:
- training data is limited
- the house is in a new neighborhood
- market conditions changed
The neural network( even “LLM” )still confidently says:
$500,000It never says:
I am not sure.This is dangerous.
Scientists Don’t Predict Like That
Suppose a weather scientist predicts tomorrow’s temperature.
They don’t say:
Tomorrow = 30°CInstead they say:
30°C ± 3°COr:
80% chance temperature is between 27°C and 33°CScientists acknowledge uncertainty.
Machine learning models should too.
A Story About Weight Values
Consider the simplest regression model.
y = wx + b
Suppose after training we get:
w = 2.5
b = 10Traditional machine learning says:
These are the correct values.
But are they really?
Maybe:
w = 2.4works almost equally well.
Maybe:
w = 2.6is also plausible.
There may be thousands of good solutions.
Why pretend only one is correct?
Enter Bayesian Thinking
Bayesian statistics says:
Don’t learn one weight.
Learn a probability distribution over weights.
Instead of:
w = 2.5we learn:
w ~ Normal(2.5, 0.2)Meaning:
- most likely around 2.5
- but could be 2.3
- could be 2.7
Now the model admits uncertainty.
This is much closer to how real scientists think.
From Neural Network to Bayesian Neural Network
Traditional Neural Network:
Input
↓
Linear Layer
↓
ReLU
↓
Linear Layer
↓
OutputWeights:
W1 = fixed number
W2 = fixed numberBayesian Neural Network:
Input
↓
Distribution of W1
↓
ReLU
↓
Distribution of W2
↓
Output DistributionWeights become random variables.
W1 ~ Normal(0,1)
W2 ~ Normal(0,1)Instead of learning one network:
Network #1we effectively learn millions of possible networks.
Example 1: House Price Prediction
full code available here: https://github.com/sankhoroy/my_medium_articles/blob/main/bayesian_nn_based_house_price_prediction.py
Suppose the input house has:
Area = 2000 sq ftTraditional Neural Network:
Price = $500,000Bayesian Neural Network:
Mean Price = $500,00095% Confidence Interval:
[$450,000 , $550,000]Now we know uncertainty.
Get sankho roy’s stories in your inbox
Join Medium for free to get updates from this writer.
This is much more useful.
A bank can make safer lending decisions.
An investor can estimate risk.
A scientist can understand confidence.
Why Bayesian Neural Networks Are Powerful
They answer two questions.
Question 1:
What is the prediction?Question 2:
How certain are we?Traditional neural networks answer only Question 1.
Bayesian neural networks answer both.
Converting a Neural Network Regression Problem
Let’s start with a standard PyTorch regression model.
import torch
import torch.nn as nn
class Regressor(nn.Module):
def __init__(self):
super().__init__()
self.net = nn.Sequential(
nn.Linear(1,32),
nn.ReLU(),
nn.Linear(32,1)
)
def forward(self,x):
return self.net(x)Prediction:
y_pred = model(x)Single output.
No uncertainty.
Bayesian Version Using Pyro
Pyro is Uber’s probabilistic programming framework built on top of PyTorch.
Instead of fixed weights:
weight = parameterwe define:
weight ~ distributionBayesian Neural Network
full code available here : https://github.com/sankhoroy/my_medium_articles/blob/main/bayesian_nn_based_house_price_prediction.py
import torch
import pyro
import pyro.distributions as dist
def model(x, y=None):
w1 = pyro.sample(
"w1",
dist.Normal(
torch.zeros(1,32),
torch.ones(1,32)
).to_event(2)
)
b1 = pyro.sample(
"b1",
dist.Normal(
torch.zeros(32),
torch.ones(32)
).to_event(1)
)
hidden = torch.relu(x @ w1 + b1)
w2 = pyro.sample(
"w2",
dist.Normal(
torch.zeros(32,1),
torch.ones(32,1)
).to_event(2)
)
b2 = pyro.sample(
"b2",
dist.Normal(
torch.zeros(1),
torch.ones(1)
).to_event(1)
)
mean = hidden @ w2 + b2
sigma = 5.0
with pyro.plate("data", len(x)):
pyro.sample(
"obs",
dist.Normal(mean.squeeze(), sigma),
obs=y
)Notice the difference.
We never declare:
w = 2.5Instead:
w ~ Normal(...)The model reasons over many possible weights.
Training with Variational Inference
Exact Bayesian inference is expensive.
Pyro uses Variational Inference.
Think of it as:
True posterior
P(weights | data)
≈
Approximate posterior
Q(weights)Training minimizes:
Difference between P and Qusing gradient descent.
Training Code
from pyro.infer import SVI
from pyro.infer import Trace_ELBO
from pyro.optim import Adam
optimizer = Adam({"lr":0.01})
svi = SVI(
model,
guide,
optimizer,
loss=Trace_ELBO()
)
for step in range(5000):
loss = svi.step(x_train, y_train)
if step % 500 == 0:
print(loss)Looks very similar to deep learning.
But now we’re learning probability distributions.
Prediction Time
Traditional Neural Network:
One forward passBayesian Neural Network:
Many forward passesEach pass samples new weights.
Prediction #1 = 495000
Prediction #2 = 505000
Prediction #3 = 490000
Prediction #4 = 520000Eventually:
Mean = 502000Std = 12000Now we know both:
- expected value
- uncertainty
Why This Matters
Imagine predicting:
- stock prices
- medical diagnosis
- autonomous driving
- aircraft failures
- loan defaults
A wrong prediction can be expensive.
Sometimes uncertainty is more important than the prediction itself.
If a model says:
Probability of cancer = 51%you would also want to know:
How confident are you?Bayesian models provide that answer.
The Real Difference
Traditional Neural Networks say:
“The answer is 500.”
Bayesian Neural Networks say:
“The answer is probably around 500, but there is a reasonable chance it lies between 450 and 550.”
One behaves like an astrologer.
The other behaves like a scientist.
Final Thoughts
Machine learning is often described as prediction.
But real science is not just prediction.
Science is prediction with quantified uncertainty.
The future is inherently uncertain.
Data is noisy.
Measurements are imperfect.
Models are incomplete.
Bayesian Neural Networks embrace this reality instead of hiding it.
That is why Bayesian machine learning feels less like fortune-telling and more like science.
We are not astrologers.
We are machine learning scientists.








