Where do squared error and cross-entropy actually come from?

Where do squared error and cross-entropy actually come from?

Leader ●7 ●28 ●72
calendar_today • schedule1 min read

Short answer: maximum likelihood. Choose a distribution for the output, then:

  1. Read its parameter as the network's output → output function
  2. Take −log of it → error function

Gaussian (regression)

  • Output: ŷ = Wᵀh + b (the mean)
  • Error: −log N(y; ŷ, σ²) → squared error (constants drop out)

Bernoulli (binary classification)

  • Output: exponentiate + normalize → ŷ = σ(z)
  • Error: −log P(y) → cross-entropy = softplus((1 − 2y)z)

Why the pairing matters: with cross-entropy, the log cancels the sigmoid's exponential, so ∂J/∂z = σ(z) − y. With squared error, σ′(z) stays in the gradient and goes to ~0 when the model is confidently wrong, so learning stalls.

Full derivations: https://husseinmahdi.xyz/writing/series/math-behind-neural-networks/

Next up: softmax + cross-entropy for k classes.

5 Comments

2 votes
2
2 votes
2 votes
0
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

Cisco's Amy Chang: A Model's "Passport" Doesn't Tell You Where It Actually Came From

Tom Smithverified - Aug 27

Everyone says DeepSeek is cheaper, but I got tired of guessing the exact math. So I built a calculat

abarth23 - Apr 27

Python for commerce students, from a former bio kid

rahuldk1105 - Oct 30

The Math Behind Neural Networks, Part 1.3 — Where the Loss Function Comes From

Hussein Mahdi - Aug 18

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19
chevron_left
4.9k Points • 107 Badges
19Posts
72Comments
14Connections
Research Engineer at @Era-Vision.| .NET | Java | Efficient Deep Learning | Complex & Higher-Order Networks | https://husseinmahdi.xyz

Commenters (This Week)

9 comments
8 comments
5 comments

Contribute meaningful comments to climb the leaderboard and earn badges!