Machine LearningClassification Metrics
Log Loss vs Brier Score
Question 291 of 303 · Updated
On this page
- 1. What do they measure?
- 2. The formulas
- Binary Log Loss
- Binary Brier Score
- 3. Numerical comparison: confidence matters
- 4. The main difference: penalty shape
- 5. Calibration versus discrimination
- 6. What about class imbalance?
- 7. Multiclass classification
- 8. Python examples with scikit-learn
- 1 = fraud, 0 = legitimate
- Columns are ordered as ["bird", "cat", "dog"]
- 9. Limitations and common mistakes
- 10. Which metric should you choose?
- Key takeaway
Log Loss and Brier Score are proper scoring rules for evaluating predicted probabilities. Both reward honest probability estimates, but they penalize errors differently: Log Loss uses a logarithmic penalty that grows without bound for a confidently wrong prediction, while Brier Score uses squared error and is bounded.
Use them to evaluate probability forecasts—not just the final class labels.
1. What do they measure?#
Suppose a fraud model predicts a 90% probability that a transaction is fraudulent.
- Log Loss asks how much probability the model assigned to the outcome that actually happened, using a logarithmic penalty.
- Brier Score asks how far the predicted probability was from the observed 0/1 outcome, using squared error.
Both are evaluated over a set of labeled examples. Lower is better, and zero represents perfect predictions on the evaluated observations.
Both are strictly proper scoring rules: in expectation, a model minimizes its score by reporting the true conditional probabilities. This makes them suitable for evaluating probabilistic forecasts rather than encouraging systematically distorted confidence.
2. The formulas#
Binary Log Loss#
For observation i:
LogLoss_i = -[y_i ln(p_i) + (1-y_i) ln(1-p_i)]
Where:
y_iis the actual label (0 or 1).p_iis the predicted probability of class 1.lnis the natural logarithm.
For N observations, mean Log Loss is:
If the actual label is 1, the loss is -ln(p). If it is 0, the loss is -ln(1-p).
Binary Brier Score#
It is simply the mean squared difference between the predicted positive-class probability and the binary outcome.
For the conventional binary definition, the score ranges from 0 to 1.
3. Numerical comparison: confidence matters#
Consider one transaction with predicted fraud probability p = 0.90.
Case A — fraud really occurred (y = 1)
- Log Loss =
- Brier =
Both reward the confident, correct prediction with a small loss.
Case B — transaction was legitimate (y = 0)
- Log Loss =
- Brier =
Both penalize the wrong prediction. Log Loss makes the penalty grow much more sharply as the model assigns almost zero probability to the outcome that actually occurs.
Compare a few probabilities for an actual positive outcome:
| Predicted probability | Log Loss | Brier |
|---|---|---|
| 0.90 | 0.105 | 0.010 |
| 0.60 | 0.511 | 0.160 |
| 0.10 | 2.303 | 0.810 |
| 0.01 | 4.605 | 0.980 |
The two scores are on different scales, so do not compare their raw numerical values with each other. Compare models using the same metric, target definition, evaluation examples, and scoring convention.
4. The main difference: penalty shape#
Log Loss
- Penalizes confident mistakes very strongly.
- Is unbounded above: as the probability assigned to the true class approaches zero, the loss approaches infinity.
- Is useful when extremely overconfident errors are especially costly.
- Can be sensitive to a small number of extreme predictions.
Brier Score
- Penalizes the squared probability error.
- Is bounded for binary classification (0 to 1 under the conventional definition).
- Is often easier to interpret as a mean squared probability error.
- Does not escalate as sharply as Log Loss for probabilities close to the wrong extreme.
Neither metric is universally better. Their different penalty shapes can lead them to rank two models differently.
5. Calibration versus discrimination#
These terms describe different properties:
- Calibration (reliability): among predictions assigned probability 0.70, does the event occur about 70% of the time over a sufficiently large, relevant group?
- Discrimination (resolution): can the model distinguish higher-risk cases from lower-risk cases and separate positives from negatives?
A crucial point: neither Log Loss nor Brier Score isolates calibration by itself. Both are overall proper scores affected by probability reliability and the model's ability to provide informative, discriminating forecasts. A better aggregate score does not prove that calibration alone improved.
The Brier Score has a well-known decomposition into:
- Reliability: the penalty for disagreement between forecast probabilities and observed frequencies.
- Resolution: the benefit from groups whose event frequencies differ from the overall event rate.
- Uncertainty: the baseline uncertainty associated with the event prevalence.
In the common decomposition, Brier Score = Reliability − Resolution + Uncertainty.
Use reliability diagrams or calibration curves to inspect calibration directly. Use ranking metrics such as ROC-AUC or PR-AUC to inspect discrimination. Evaluate these alongside proper scoring rules rather than treating one score as a complete diagnosis.
6. What about class imbalance?#
Class imbalance affects interpretation of both metrics.
For example, if only 1% of transactions are fraudulent, a model that predicts 1% fraud probability for every transaction may achieve a deceptively respectable aggregate score while being useless for identifying individual high-risk cases.
Practical checks:
- Compare against a simple prevalence-based probability baseline.
- Report performance on the same representative test population.
- Inspect positive-class and important subgroup behavior, not only one aggregate number.
- Track prevalence changes over time; a score can change because the population changed.
- Keep probability evaluation separate from threshold-based business costs.
Do not assume that class weighting automatically improves probability quality. Training with class-weighted losses can shift the probability scale toward a reweighted class distribution. If deployment needs probabilities for the real population, validate and, where necessary, recalibrate them on representative data.
7. Multiclass classification#
Both metrics extend beyond binary classification, but their formulas differ in how they use the probability vector.
For K mutually exclusive classes, let y_ic be 1 when observation i belongs to class c and 0 otherwise, and let p_ic be the predicted probability for that class.
Multiclass Log Loss uses only the probability assigned to the true class for each observation:
Multiclass Brier Score compares the complete probability vector with the one-hot true label:
Example: the true class is Cat, and the model predicts [Cat=0.70, Dog=0.20, Bird=0.10].
- Log Loss =
- Brier contribution =
Watch the Brier scaling convention. The conventional unscaled multiclass sum ranges from 0 to 2. Binary Brier is commonly divided by two and reported from 0 to 1. In current scikit-learn, scale_by_half="auto" applies the halving to binary data but retains the 0-to-2 convention for multiclass data. State the convention whenever reporting or comparing multiclass scores.
8. Python examples with scikit-learn#
Use probabilities from predict_proba, not hard class predictions.
```python from sklearn.metrics import log_loss, brier_score_loss
1 = fraud, 0 = legitimate#
y_true = [1, 0, 1, 0] y_prob = [0.90, 0.20, 0.60, 0.10]
print("Log Loss:", log_loss(y_true, y_prob)) print( "Brier:", brier_score_loss(y_true, y_prob, pos_label=1) ) ```
For multiclass classification:
```python from sklearn.metrics import log_loss, brier_score_loss
y_true = ["cat", "dog", "bird"]
Columns are ordered as ["bird", "cat", "dog"]#
y_proba = [ [0.10, 0.70, 0.20], [0.10, 0.20, 0.70], [0.80, 0.10, 0.10], ]
print("Log Loss:", log_loss( y_true, y_proba, labels=["bird", "cat", "dog"] ))
print("Brier:", brier_score_loss( y_true, y_proba, labels=["bird", "cat", "dog"], scale_by_half="auto" )) ```
Keep class-column order aligned with the labels. Check the installed scikit-learn version: the scale_by_half option was added in version 1.7, and the current API uses y_proba for Log Loss probabilities.
9. Limitations and common mistakes#
- Different scales: Log Loss and Brier values are not directly comparable. Compare models within each metric.
- One score is not a diagnosis: neither score alone tells you whether the problem is calibration, discrimination, data quality, or population shift.
- Outliers and extreme confidence: Log Loss can be dominated by a few confidently wrong predictions. Inspect those cases instead of hiding them.
- Prevalence dependence: both scores depend on the target distribution. Include a suitable baseline and evaluate on a representative sample.
- Multiclass conventions: Brier scaling differs between binary and multiclass settings. Record the definition and library settings.
- Thresholds and costs: neither metric chooses a deployment threshold or encodes the business cost of false positives and false negatives.
- Leakage: use held-out or out-of-fold predictions. Do not evaluate on the same examples used to fit or calibrate the model.
10. Which metric should you choose?#
Choose Log Loss when:
- You need to strongly penalize confident probability errors.
- You are comparing probabilistic classifiers for likelihood-based objectives.
- Reliable probability estimates matter for downstream decisions, ranking by expected risk, or probabilistic aggregation.
Choose Brier Score when:
- You want a bounded squared-probability-error measure.
- You want an intuitive measure of how far probabilities are from observed outcomes.
- You want to use the Brier decomposition to study reliability, resolution, and uncertainty.
For high-stakes production systems, it is often useful to report both. Add calibration curves, ROC-AUC or PR-AUC, subgroup metrics, a prevalence baseline, and threshold-specific business measures. Re-evaluate after changes in prevalence, customer mix, or operating policy.
Key takeaway#
Log Loss punishes confident wrong probabilities more aggressively; Brier Score measures squared probability error and is bounded. Both are strictly proper scoring rules for probabilistic predictions, and neither should be mistaken for a calibration-only or discrimination-only metric. Choose based on the risk you want the score to emphasize, and use complementary diagnostics before deploying a model.
Interview answer: Log Loss uses the negative logarithm of the probability assigned to the true class, so confident mistakes receive very large penalties. Brier Score averages squared differences between predicted probabilities and one-hot outcomes, giving a bounded score in the binary case. Both reward honest probabilities, but they have different penalty shapes and neither alone isolates calibration from discrimination.
References
- 1.scikit-learn — log_loss API referencescikit-learn.org
- 2.scikit-learn — brier_score_loss API referencescikit-learn.org
- 3.
- 4.
- 5.
Related questions
Explore other topics:Deep LearningMLOps