Skip to content

[BUG] Fix issue with EncodeNormalizer(method='standard', center=False) for scale value - #1902

Merged
fnhirwa merged 4 commits into
sktime:mainfrom
fnhirwa:norm
Jul 1, 2025
Merged

[BUG] Fix issue with EncodeNormalizer(method='standard', center=False) for scale value#1902
fnhirwa merged 4 commits into
sktime:mainfrom
fnhirwa:norm

Conversation

@fnhirwa

@fnhirwa fnhirwa commented Jun 25, 2025

Copy link
Copy Markdown
Member

Fixes #1901
This PR fixes the issue with

encoder = EncoderNormalizer(
    method='standard',
    center=False,
    max_length=None,
    transformation=None,
    method_kwargs={}
)

which was returning scale_ as mean of x instead its std

Temporarily backported lazywhere implementation from scipy._lib._util. to avoid import errors in the statsmodels with the latest scipy version.

Comment thread tests/test_metrics.py
assert torch.isclose(target.mean(), samples.mean(), atol=0.1, rtol=0.5)
assert torch.isclose(target.std(), samples.std(), atol=0.1, rtol=0.5)
if transformation == "log1p" and not center:
assert torch.isclose(target.std(), samples.std(), atol=0.1, rtol=0.8)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variance distorts when the data is not centered, as the log1p transformation is log(1+x)

@fnhirwa
fnhirwa marked this pull request as ready for review June 25, 2025 13:51
@fkiraly fkiraly added the bug Something isn't working label Jun 25, 2025
@codecov

codecov Bot commented Jun 25, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 27.27273% with 8 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@b2cfc14). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...sting/models/temporal_fusion_transformer/tuning.py 27.27% 8 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1902   +/-   ##
=======================================
  Coverage        ?   86.25%           
=======================================
  Files           ?       96           
  Lines           ?     7772           
  Branches        ?        0           
=======================================
  Hits            ?     6704           
  Misses          ?     1068           
  Partials        ?        0           
Flag Coverage Δ
cpu 86.25% <27.27%> (?)
pytest 86.25% <27.27%> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

@cngmid

cngmid commented Jun 27, 2025

Copy link
Copy Markdown
Contributor

Linked to this issue, the method

    @property
    def min_length(self):
        if self.method == "identity":
            return 0  # no timeseries properties used
        elif self.center:
            return 1  # only calculation of mean required
        else:
            return 2  # requires std, i.e. at least 2 entries

of class EncoderNormalizer might also need to be reviewed.
If the method is not "identity", one always needs at least 2 entries, independently whether self.center is True or False.

@fkiraly fkiraly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me in terms of the location directly fixed, though see above comment by @cngmid

@fkiraly

fkiraly commented Jun 30, 2025

Copy link
Copy Markdown
Collaborator

FYI, if you have time to look at the __array_wrap__ issue, that would be appreciated - I tried here, but apparently I am not catching all cases that the function input may have: #1855

@fnhirwa

fnhirwa commented Jul 1, 2025

Copy link
Copy Markdown
Member Author

FYI, if you have time to look at the __array_wrap__ issue, that would be appreciated - I tried here, but apparently I am not catching all cases that the function input may have: #1855

sure will look into this🤞

@fnhirwa
fnhirwa merged commit cae3174 into sktime:main Jul 1, 2025
34 of 35 checks passed
@fnhirwa
fnhirwa deleted the norm branch July 10, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Fixed/resolved

Development

Successfully merging this pull request may close these issues.

[BUG] EncoderNormalizer(method='standard', center=False) has wrong scale

3 participants