Skip to content

MSE and RMSE overflow for narrow integer target and forecast columns #337

Open

Description

Integer inputs are subtracted and squared before promotion, so valid target/forecast columns can produce an incorrect squared error. This also affects RMSE and occurs in both the pandas and Polars paths.

import numpy as np
import pandas as pd
from utilsforecast.losses import mse, rmse

df = pd.DataFrame({
    "unique_id": ["a", "a"],
    "y": np.array([100, 100], dtype=np.int8),
    "model": np.array([-100, -100], dtype=np.int8),
})
print(mse(df, models=["model"]))   # expected model = 40000
print(rmse(df, models=["model"]))  # expected model = 200

I reproduced this against main at 5a6ec8d. Tests covering int8, uint8 and int32, both backends, and cutoff grouping fail before promoting the operands to Float64 and pass afterward. The fix promotes both operands before subtraction; it does not claim exact arithmetic for integers beyond float64's precision.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions