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

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

Leader ●9 ●30 ●73
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.

Want more #ai & #machine-learning deep dives?

Join 6,053+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

5 Comments

2 votes
2
2 votes
2 votes
0

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

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

Hussein Mahdi - Aug 18

Python for commerce students, from a former bio kid

rahuldk1105 - Oct 30

The Math Behind Neural Networks, Explained Like Nobody Did for Me - Part 1.2

Hussein Mahdi - Jul 27
chevron_left
5.3k Points • 112 Badges
19Posts
79Comments
14Connections
Research Engineer at @Era-Vision.| .NET | Java | Efficient Deep Learning | Complex & Higher-Order Networks | https://husseinmahdi.xyz

Commenters (This Week)

2 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!