3.1.8 · D1Neural Network Fundamentals

Foundations — Loss functions - MSE, cross-entropy

2,359 words11 min readBack to topic

This page assumes you have seen none of the notation on the parent note the Loss Functions topic. We will earn every symbol before it is used. Read top to bottom; each block leans only on the ones above it.


0. The two actors: prediction and truth

Everything starts with two numbers.


1. Subscripts and the summation sign

We rarely have one prediction — we have many. We need notation for "the -th one" and for "add them all up".


2. The square — the first magnifying glass

The raw error has a problem: sometimes it is negative (guess too high), sometimes positive (guess too low). If we just added them, a and a would cancel to and hide two bad guesses.

This "square bowl" is the entire shape of MSE. Its lowest point sits exactly where guess equals truth (), which is precisely the point training tries to reach.


3. Probabilities — for guessing categories

MSE works when the answer is a plain number (a price, a temperature). But for classification — "cat or dog?" — the network instead outputs a probability: a number between 0 and 1 saying how sure it is.


4. The logarithm — and why it always means "natural log" () here

For probabilities we do not use the square. We use the logarithm, because it answers a different question: "how surprised should I be?" Before anything else we must pin down its base.


5. One-hot labels, the class index , and the exponent trick

Three last pieces of notation let the compact formulas on the parent note make sense.


6. Argmax, argmin, and — the language of "best choice"


Prerequisite map

Read this map as "which small idea you must own before the arrow's target makes sense". It restates, in one glance, the exact notation chain of this page: the two dots () give an error, the square turns it into MSE; probabilities plus plus the one-hot label give cross-entropy; and with turns either loss into training.

prediction y-hat and truth y

error gap y minus y-hat (sec 0)

square makes a bowl (sec 2)

index i and sum sigma (sec 1)

average one over n (sec 1)

MSE loss

probability in zero to one (sec 3)

natural log ln equals surprise (sec 4)

minus ln is badness (sec 4)

one-hot label and index k (sec 5)

cross entropy loss

theta the dials (sec 6)

argmin find best dials (sec 6)

training the network


Equipment checklist

Test yourself — cover the right side and answer out loud.

What does the hat in always mean?
"The machine's guess of" — a prediction.
What is the error between truth and prediction?
The gap .
In , what do the bottom and top numbers mean?
Where the counter starts () and where it stops ().
How do you turn a sum of numbers into an average?
Multiply by (sum then divide).
Give two reasons MSE squares the error.
To remove the sign, and to punish big errors much harder.
What range must a probability live in?
Strictly between 0 and 1.
When ML writes "", which base does it mean?
Natural log , base .
What is , and what does that represent?
— zero surprise at a certain, correct guess.
What happens to as ?
It plunges to (infinite surprise).
Why do we put a minus sign in ?
Log of a probability is negative; the minus makes loss a positive "badness".
What do and count in cross-entropy?
counts classes from to ; is the number of classes.
In a one-hot label, how many entries are 1?
Exactly one — the correct class.
Why does collapse to one term?
The zeros in the one-hot label kill every non-true class.
Expand .
— binary cross-entropy.
What does stand for?
All the network's tunable weights (its dials).
What does ask for?
The dial settings that make the loss smallest.

Once every answer feels easy, you are ready for the parent note Loss functions - MSE, cross-entropy (index 3.1.8), and the deeper machinery in Maximum Likelihood Estimation and Logistic Regression.