Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 1, 2025

Conversation

fnhirwa
Copy link
Member

@fnhirwa fnhirwa commented Jun 25, 2025

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.

@@ -191,7 +191,10 @@ def test_NegativeBinomialDistributionLoss(center, transformation):
)
samples = loss.sample(rescaled_parameters, 1)
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
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
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

Attention: 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
Copy link
Contributor

cngmid commented Jun 27, 2025

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.

Copy link
Collaborator

@fkiraly fkiraly left a comment

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
Copy link
Collaborator

fkiraly commented Jun 30, 2025

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
Copy link
Member Author

fnhirwa commented Jul 1, 2025

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
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