Skip to content

Fix MeanEstimator to ignore NaNs in training data - #3329

Open
SalahnAI wants to merge 1 commit into
awslabs:devfrom
SalahnAI:fix/mean-estimator-ignore-nan
Open

Fix MeanEstimator to ignore NaNs in training data#3329
SalahnAI wants to merge 1 commit into
awslabs:devfrom
SalahnAI:fix/mean-estimator-ignore-nan

Conversation

@SalahnAI

@SalahnAI SalahnAI commented Jul 29, 2026

Copy link
Copy Markdown

Description

A single NaN anywhere in the training data caused MeanEstimator to produce all-NaN forecasts for every series, because the per-timestep mean over series is computed with ndarray.mean. As reported in #2175, one missing value in one series poisons all metrics for the whole backtest.

This PR switches the computation to np.nanmean, which is already the convention used by MeanPredictor and MovingAveragePredictor in the same module, so MeanEstimator now behaves consistently with its neighbors.

It also adds tests for MeanEstimator (previously untested), including the NaN cases: a partially-NaN series and an all-NaN series.

Fixes #2175

Testing

pytest test/model/trivial/ — 35 passed (4 new).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

A single NaN in any training series caused MeanEstimator to produce
all-NaN forecasts, because the per-timestep mean over series was
computed with ndarray.mean. Use np.nanmean instead, consistent with
MeanPredictor and MovingAveragePredictor in the same module, and add
tests for MeanEstimator (previously untested), including the NaN case.

Fixes awslabs#2175
@SalahnAI
SalahnAI force-pushed the fix/mean-estimator-ignore-nan branch from 0901f07 to 70895f5 Compare July 29, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MeanEstimator should be able to ignore NANs in training

1 participant