RankedProbabilityScore¶
yohou.metrics.class_proba.RankedProbabilityScore
¶
Bases: BaseClassProbaScorer
Ranked Probability Score for class-probability forecasts.
Measures the quality of predicted probability distributions for ordered (ordinal) classes by comparing cumulative probability distributions. Generalizes the Brier score to ordinal multi-class settings by penalizing predictions that place probability mass far from the true class.
The RPS for a single observation is:
where \(\hat{p}_j\) is the predicted probability for class \(j\), \(o_j\) is 1 if the true class is \(j\) and 0 otherwise, and \(K\) is the number of classes. The normalization by \(K-1\) follows the standard forecasting convention.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
class_order
|
list of str or None
|
Explicit ordering of class labels for the cumulative sum. When
None, classes are ordered by their column order in |
None
|
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). |
None
|
components
|
list of str, dict of str to float, or None
|
Component filter (list) or filter with weights (dict). |
None
|
Attributes¶
| Name | Type | Description |
|---|---|---|
lower_is_better |
bool
|
Always True for RPS. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import RankedProbabilityScore
>>> 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 = RankedProbabilityScore()
>>> _ = scorer.fit(y_true)
>>> scorer.score(y_true, y_pred)
0.041...
Notes¶
- RPS is a proper scoring rule for ordinal outcomes.
- For K=2, RPS equals the Brier score (up to normalization).
- Sensitive to the distance between predicted and true class in the ordinal ranking, unlike Brier score which treats all misclassifications equally.
- The
class_orderparameter lets you specify a meaningful ordering for ordinal variables (e.g.["low", "medium", "high"]).
See Also¶
BrierScore: Brier score (unordered multi-class).LogLoss: Logarithmic loss (cross-entropy).
Source Code¶
Show/Hide source
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |