Skip to content

[BUG] normalize y when using EncoderNormalizer - #2396

Open
CodingSelim wants to merge 1 commit into
sktime:mainfrom
CodingSelim:bug/2360-normalize-y-encoder-normalizer
Open

[BUG] normalize y when using EncoderNormalizer#2396
CodingSelim wants to merge 1 commit into
sktime:mainfrom
CodingSelim:bug/2360-normalize-y-encoder-normalizer

Conversation

@CodingSelim

Copy link
Copy Markdown

Reference Issues/PRs

Fixes #2360.

What does this implement/fix? Explain your changes.

y came out raw when the target normalizer is fitted per sequence. the encoder window gets normalized through fit_transform_sequence but the decoder indices were never touched, so with EncoderNormalizer the model trains against targets on a completely different scale to its inputs:

target_past (normalized) -> min -1.525 max 1.525
y                        -> min 220.000 max 270.000

the decoder cant just call fit_transform_sequence too, that would refit on the decoder window and leak. it needs to reuse whatever was fitted on the encoder window a few lines up, so i added ScalerAdapter.transform_sequence as the transform only counterpart, same shape as fit_transform_sequence, per sequence sub normalizers transform and everything else passes through since those already had their global state applied during preprocessing. then y goes through it.

going through the whole MultiNormalizer instead doesnt work, a GroupNormalizer sub wants the group columns and throws either target_scale or X has to be passed, which is what test_multivariate_target[normalizer_list2] catches.

What should a reviewer concentrate their feedback on?

  • whether transform_sequence belongs on ScalerAdapter or somewhere else
  • the pass through for non per sequence sub normalizers, im assuming preprocessing already normalized those columns so the decoder shouldnt touch them again

Did you add any tests for the change?

yes, test_encoder_normalizer_normalizes_y. it fails on main with assert tensor(270.) < 10.0 and passes here. uses a linear series so the check is exact, y has to be off the raw scale and carry on from the last encoder value by the same constant step.

pytest tests/test_data/ gives 177 passed on main and 178 with this, so just the one new test and nothing else moved. ruff format and check clean on the pinned 0.6.9.

Any other comments?

PR checklist

  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG].
  • Added/modified tests
  • Used pre-commit hooks when committing to ensure that code is compliant with hooks.

EncoderDecoderTimeSeriesDataModule fitted the per-sequence normalizer on the
encoder window and normalized target_past, but left y on the raw scale. Adds
ScalerAdapter.transform_sequence so the decoder window reuses the state fitted
on the encoder window instead of refitting, and applies it to y.
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@36ac67f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pytorch_forecasting/adapters/scaler_adapters.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2396   +/-   ##
=======================================
  Coverage        ?   88.16%           
=======================================
  Files           ?      196           
  Lines           ?    11065           
  Branches        ?        0           
=======================================
  Hits            ?     9756           
  Misses          ?     1309           
  Partials        ?        0           
Flag Coverage Δ
cpu 88.16% <92.85%> (?)
pytest 88.16% <92.85%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[BUG] y not being normalized when using EncoderNormalizer in EncoderDecoderDataModule

1 participant