LogLoss¶
yohou.metrics.class_proba.LogLoss
¶
Bases: BaseClassProbaScorer
Logarithmic loss (cross-entropy) for class-probability forecasts.
Measures the quality of predicted probability distributions by computing the negative log-likelihood of the true class under the predicted distribution.
The log loss for a single observation is:
where \(\\hat{p}_{i,y_i}\) is the predicted probability assigned to the true class \(y_i\) for observation \(i\).
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
aggregation_method
|
list of str or str
|
Dimensions to aggregate over. See |
"all"
|
groups
|
list of str, dict of str to float, or None
|
Panel group filter (list) or filter with weights (dict). See |
None
|
components
|
list of str, dict of str to float, or None
|
Component filter (list) or filter with weights (dict). See |
None
|
Attributes¶
| Name | Type | Description |
|---|---|---|
lower_is_better |
bool
|
Always True for LogLoss. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import LogLoss
>>> y_true = pl.DataFrame({
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
... "weather": ["sunny", "rainy", "cloudy"],
... })
>>> y_pred = pl.DataFrame({
... "vintage_time": [datetime(2019, 12, 31)] * 3,
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
... "weather_proba_sunny": [0.7, 0.1, 0.2],
... "weather_proba_rainy": [0.2, 0.8, 0.1],
... "weather_proba_cloudy": [0.1, 0.1, 0.7],
... })
>>> scorer = LogLoss()
>>> _ = scorer.fit(y_true)
>>> scorer.score(y_true, y_pred)
0.312...
Notes¶
- Lower values indicate better calibrated probability estimates.
- Heavily penalizes confident wrong predictions (assigning near-zero probability to the true class).
- Probabilities are clipped to
[1e-15, 1 - 1e-15]to avoid numerical issues withlog(0).
See Also¶
BrierScore: Multi-class Brier score.Accuracy: Classification accuracy from argmax.
Source Code¶
Show/Hide source
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
Tutorials¶
The following example notebooks use this component:
-
How to Score Class-Probability Forecasts
Evaluation-Search
Evaluate categorical forecasts with LogLoss, BrierScore, and Accuracy. Covers per-timestep scoring, aggregation modes, and reliability diagrams.
-
How to Forecast Class Probabilities
Forecasting-Models
Use ClassProbaReductionForecaster to produce calibrated probability forecasts and evaluate them with Brier score, log loss, and accuracy.
-
How to Combine Classification Forecasters
Forecasting-Models
Build classification ensembles with VotingClassProbaForecaster using soft and hard voting strategies.