A small blog post on how to teach your model to output their prediction-confidence
In classification, confidence is built into the output: the model predicts a probability distribution over classes. When it is confident, the distribution becomes sharp (one class gets most of the mass). When it is uncertain, the distribution becomes flatter.
But what happens when the target is not a class, but a vector?
With plain MSE, the model outputs only a point estimate, so confidence is not explicit.
Can a regression model predict both the target value and its uncertainty?
The answer is yes! To recover that notion of confidence in regression, we make the model predict a full distribution, not just its mean.
Suppose we have some datapoints and we want to predict the ground truth probability $p(y|x)$.
We don't have direct access to $p$, so we are going to approximate $p(y|x)$ with $q(y|x)$ where is a gaussian where the mean and the variance are learned functions $\mu_\theta(x)$ and $\sigma_\phi(x)$
$$
q(y|x) = \frac {1}{\sqrt{2 \pi \sigma_\phi^2}} \exp -\frac{(y-\mu_\theta)^2}{2\sigma_\phi^2}
$$
The loss is simply going to be the negative log likelyhood of $q(y|x)$
$$
L = -\log q(y|x) = -\log\left[\frac {1}{\sqrt{2 \pi \sigma_\phi^2}} \exp -\frac{(y-\mu_\theta)^2}{2\sigma_\phi^2}\right]
$$
Doing some simple calculations, get that the loss is equal to (up to some constant)
Now let's train a model with this loss!
Suppose that the average value of $y$ is linearly dependent on $x$, i.e., $\mu = a x + b$, and the dispersion around the mean is also linearly dependent on $x$, i.e., $\sigma = |c x + d|$. This means that $$ p(y|x) = \mathcal{N}\!\left[a x + b, (c x + d)^2\right] $$
As you can see the model is able to describe perfectly the ground truth probability distribution by minimizing the loss. Now let's analyze the math to get a better insight on why this is the case.
From the loss in equation
This means that the gradient to find the expected value of $y$ is exactly the same as the one of the $L_2$ loss, but here each sample is weighted by the expect sample error $\sigma_\phi$- Which is exactly what you want!
The problem with equation
This theory has been around for quite a while
As you can see the areas where the model is less precise (mainly some edges and tree leafs) are highlighed in the uncertanty heatmap.
The way this is done implementation-wise is super simple: you just output 6-channels per pixel: one for the RGB values and one for their uncertainty.
Uncertainty-aware regression gives the model two outputs that matter in practice: prediction and confidence. This small change allows us to estimate pixel-wise uncertainty.
This was originally part of a larger blog post
You can do so by sending an email to this address francesco215@live.it or by messaging on discord at sacco215
For attribution in academic contexts, please cite this work as
Sacco, "How to Predict Uncertainty", zenodo, 2026
BibTeX citation
@article{sacco2026Uncertainty,
author = {Sacco, Francesco},
title= {How to Predict Uncertainty},
journal = {Zenodo},
year = {2026},
doi = {10.5281/zenodo.22261724},
url = {francesco215.github.io/autoregressive_diffusion/uncertainty.html}
}