Cross-Entropy
๐ Cross-Entropy
What is Cross-Entropy?
Cross-entropy measures how well a predicted probability distribution matches the true distribution.
-
Small value → prediction is good
-
Large value → prediction is poor
๐ It is widely used as a loss function in machine learning (classification, neural networks, logistic regression).
Mathematical Definition
For true distribution and predicted distribution :
-
= true probability
-
= predicted probability
Intuition
Think of cross-entropy as:
“How surprised are we if predictions are used while reality is ?”
-
If prediction assigns high probability to the correct class → low surprise → low loss
-
If prediction assigns low probability to correct class → high surprise → high loss
Simple Coin Example
✅ True distribution (actual)
(The coin actually came up Heads)
✅ Case 1 — Good prediction
✔ Small cross-entropy → good prediction
❌ Case 2 — Bad prediction
❌ Large cross-entropy → poor prediction
Classification Example (Machine Learning)
Suppose a model predicts probabilities for 3 classes:
| Class | True P | Predicted Q |
|---|---|---|
| Cat | 1 | 0.7 |
| Dog | 0 | 0.2 |
| Rabbit | 0 | 0.1 |
If the model predicted:
| Cat | 0.1 |
๐ Much worse prediction → larger loss.
Python Code Example
Why Cross-Entropy is Used in ML
✔ Smooth and differentiable → good for gradient descent
✔ Penalizes confident wrong predictions heavily
✔ Works naturally with probability outputs (softmax/sigmoid)
Summary
Cross-entropy = penalty for predicting the wrong probabilities.
Comments
Post a Comment