Accuracy¶
yohou.metrics.Accuracy
¶
Bases: BaseHardLabelScorer
Categorical accuracy from class-probability forecasts.
Computes the fraction of time steps where the predicted class (argmax of probabilities) matches the true class.
where \(\hat{y}_i = \arg\max_k \hat{p}_{ik}\) is the predicted class.
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 or filter with weights. |
None
|
components
|
list of str, dict of str to float, or None
|
Component filter or filter with weights. |
None
|
Attributes ¶
| Name | Type | Description |
|---|---|---|
lower_is_better |
bool
|
Always False for accuracy (higher is better). |
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics.classification import Accuracy
>>> 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 = Accuracy()
>>> _ = scorer.fit(y_true)
>>> scorer.score(y_true, y_pred)
1.0
Notes ¶
Accuracy uses micro averaging internally: TP / (TP + FP). In multiclass settings each prediction is either a TP for one class or an FP for another, so TP + FP equals the total sample count and TP / (TP + FP) = correct / N.
See Also ¶
LogLoss: Logarithmic loss (cross-entropy).BrierScore: Multi-class Brier score.Precision: Precision (positive predictive value).
Source Code ¶
Source code in src/yohou/metrics/classification.py
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 363 364 365 366 367 368 369 370 371 | |
Tutorials¶
The following example notebooks use this component:
-
Class-Probability Forecasting
Forecast air quality categories using ClassProbaReductionForecaster, producing a probability distribution over four WHO air quality classes.
-
How to Combine Classification Forecasters
Build classification ensembles with VotingClassProbaForecaster using soft and hard voting strategies.
-
How to Forecast Class Probabilities
Use ClassProbaReductionForecaster to produce calibrated probability forecasts and evaluate them with Brier score, log loss, and accuracy.
-
How to Score Class-Probability Forecasts
Evaluate categorical forecasts with LogLoss, BrierScore, and Accuracy. Covers per-timestep scoring, aggregation modes, and reliability diagrams.
-
How to Use Point Forecast Metrics
Compare MAE, MAPE, MASE, RMSE, and other point metrics across multiple forecasters with componentwise and groupwise aggregation.