MeanAbsolutePercentageError¶
yohou.metrics.point.MeanAbsolutePercentageError
¶
Bases: BasePointScorer
Mean Absolute Percentage Error metric for point forecasts.
Computes the average percentage error between predictions and actual values. This provides a scale-independent metric that enables comparison across time series with different magnitudes.
The MAPE is defined as:
where \(y_i\) is the actual value, \(\\hat{y}_i\) is the predicted value, and \(n\) is the number of observations.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
epsilon
|
float
|
Small constant added to denominator to prevent division by zero when actual values are zero or near-zero. |
1e-8
|
aggregation_method
|
list of str or str
|
Dimensions to aggregate over. Options: - "stepwise": Aggregate across forecasting steps. - "vintagewise": Aggregate across vintages (observed times). - "componentwise": Aggregate across components, return per-timestep DataFrame - "groupwise": Aggregate across panel groups (panel data only) - "all": Aggregate across all dimensions (returns scalar). Same as ["stepwise", "vintagewise", "componentwise", "groupwise"]. Example outputs: - ["stepwise", "vintagewise"]: Per-component (and per-group) DataFrame. - "componentwise" or ["componentwise"]: Per-timestep (and per-group) DataFrame. - "groupwise" or ["groupwise"]: Per-component per-timestep DataFrame (panel aggregated). - ["stepwise", "vintagewise", "componentwise"]: Scalar (global) or per-group DataFrame (panel). - "all": Scalar float (hierarchically aggregated for panel data). |
"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 MAPE. |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.metrics import MeanAbsolutePercentageError
>>> y_true = pl.DataFrame({
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
... "value": [10.0, 20.0, 30.0],
... })
>>> y_pred = pl.DataFrame({
... "vintage_time": [datetime(2019, 12, 31)] * 3,
... "time": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
... "value": [12.0, 19.0, 28.0],
... })
>>> mape = MeanAbsolutePercentageError()
>>> _ = mape.fit(y_true)
>>> mape.score(y_true, y_pred)
10.55...
Notes¶
- MAPE is scale-independent and useful for comparing forecasts across different series
- Asymmetric: penalizes over-predictions more heavily than under-predictions
- Undefined when actual values are zero; epsilon parameter prevents division by zero
- Values are expressed as percentages (0-100 scale)
- May be sensitive to very small actual values even with epsilon protection
See Also¶
SymmetricMeanAbsolutePercentageError: Symmetric version of MAPEMeanAbsoluteError: Absolute error in original unitsMeanAbsoluteScaledError: Scaled by naive forecast error
Source Code¶
Show/Hide source
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 | |
Tutorials¶
The following example notebooks use this component:
-
How to Use Point Forecast Metrics
Evaluation-Search
Compare MAE, MAPE, MASE, RMSE, and other point metrics across multiple forecasters with componentwise and groupwise aggregation.
-
How to Visualize Forecast Evaluation Results
Visualization
Use plot_calibration, plot_score_per_step, and plot_forecast to diagnose forecast accuracy and interval calibration visually.