RMSPE (Root Mean Square Percentage Error)

Eval

RMSPE (Root Mean Square Percentage Error)

Created: Last updated: Read time: 2 min
まとめ
  • RMSPE measures the root mean square of percentage errors between predictions and actuals.
  • In sales forecasting, it quantifies the average relative deviation between predicted and observed values.
  • This section explains how to handle zero values using ε and deal with low-demand cases.

1. Definition #

$$ \mathrm{RMSPE} = \sqrt{\frac{1}{n} \sum_{i=1}^n \left( \frac{y_i - \hat{y}_i}{y_i} \right)^2 } $$

In practice, it’s often multiplied by 100 to express it as a percentage.
Be cautious when actual values are close to zero, as this can cause divergence.


2. Computing in Python #

import numpy as np

def rmspe(y_true: np.ndarray, y_pred: np.ndarray, eps: float = 1e-8) -> float:
    ratios = (y_true - y_pred) / np.maximum(np.abs(y_true), eps)
    return float(np.sqrt(np.mean(ratios**2)))

y_true = np.array([120, 150, 80, 200])
y_pred = np.array([118, 148, 79, 190])
print(f"RMSPE = {rmspe(y_true, y_pred) * 100:.2f}%")

Here, eps prevents division by zero.
If zero-demand samples are frequent, consider alternatives like RMSLE or WAPE.


3. When to Use #

  • Retail demand forecasting: Focus on proportional errors in sales volume.
  • Financial risk modeling: Evaluate prediction errors in returns or price movements as percentages.
  • Energy load prediction: Assess relative deviations even when magnitudes vary widely.

4. Comparison with Other Percentage Metrics #

MetricFeatureCaution
MAPEMean percentage error; intuitiveResponds linearly to large errors
RMSPEPenalizes large relative errors more stronglyDiverges when actuals are near zero
RMSLELogarithmic scale metricSimilar to ratio-based, but harder to interpret

RMSPE emphasizes large outliers more than MAPE, making it well-suited for risk-averse KPIs.


5. Practical Considerations #

  • RMSPE can be unstable with many zero or near-zero values. Exclude or adjust such samples, or complement with other metrics.
  • Report RMSPE together with MAE or WAPE to account for both absolute and relative performance.
  • When comparing across periods, calculate RMSPE on consistent sets (same products/time frames).

Summary #

  • RMSPE captures the root mean square of percentage errors, emphasizing large deviations.
  • It’s useful for evaluating proportional risk but requires care around zeros.
  • Use alongside MAPE, WAPE, or RMSLE for a balanced view of both absolute and relative errors.