Skip to content
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

MeanEncoderTransform generates wrong values #492

Merged
merged 14 commits into from
Nov 6, 2024
Merged

MeanEncoderTransform generates wrong values #492

merged 14 commits into from
Nov 6, 2024

Conversation

egoriyaa
Copy link
Collaborator

Before submitting (must do checklist)

  • Did you read the contribution guide?
  • Did you update the docs? We use Numpy format for all the methods and classes.
  • Did you write any new necessary tests?
  • Did you update the CHANGELOG?

Proposed Changes

Closing issues

closes #490

@egoriyaa egoriyaa self-assigned this Oct 16, 2024
Copy link

github-actions bot commented Oct 16, 2024

🚀 Deployed on https://deploy-preview-492--etna-docs.netlify.app

@github-actions github-actions bot temporarily deployed to pull request October 16, 2024 04:31 Inactive
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 45.45455% with 18 lines in your changes missing coverage. Please review.

Project coverage is 90.51%. Comparing base (6cd66ae) to head (c4ca475).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
etna/transforms/encoders/mean_encoder.py 45.45% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #492      +/-   ##
==========================================
- Coverage   90.61%   90.51%   -0.10%     
==========================================
  Files         247      247              
  Lines       16486    16516      +30     
==========================================
+ Hits        14938    14950      +12     
- Misses       1548     1566      +18     

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

@github-actions github-actions bot temporarily deployed to pull request October 16, 2024 09:06 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 21, 2024 07:37 Inactive
@github-actions github-actions bot temporarily deployed to pull request November 1, 2024 08:13 Inactive
@github-actions github-actions bot temporarily deployed to pull request November 2, 2024 07:08 Inactive
@martins0n martins0n requested a review from Copilot November 5, 2024 04:49

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (2)

etna/transforms/encoders/mean_encoder.py:173

  • Ensure that the initial values of ans_cumsum and ans_cumcount are correctly handled to avoid potential issues with NaN values.
ans_cumsum = np.full_like(target, np.nan)

tests/test_transforms/test_encoders/test_mean_encoder_transform.py:34

  • Ensure that the new test cases cover all edge cases, including scenarios with multiple NaN values and different categories.
df["mean_encoded_regressor"] = [np.NaN, np.NaN, np.NaN, 1.5, 2.75, 2.25] + [np.NaN, np.NaN, 6.25, 7, 7.625, np.NaN]
@egoriyaa
Copy link
Collaborator Author

egoriyaa commented Nov 5, 2024

MeanEncoderTransform(..., mode="per-segment")

segments=2000, periods=1000

2000 * 1000 unique categories
no_numba - 75 sec, numba 25 sec

200 unique categories
no_numba - 30 sec, numba 19 sec

1 unique category
no_numba - 18 sec, numba 18 sec

MeanTransform(..., window=-1) (for comparison)

segments=2000, periods=1000

7 sec

@egoriyaa egoriyaa requested a review from d-a-bunin November 5, 2024 07:21
@github-actions github-actions bot temporarily deployed to pull request November 5, 2024 13:49 Inactive
@egoriyaa egoriyaa requested a review from d-a-bunin November 5, 2024 13:53
@github-actions github-actions bot temporarily deployed to pull request November 5, 2024 13:56 Inactive
@github-actions github-actions bot temporarily deployed to pull request November 5, 2024 14:04 Inactive

ts = TSDataset(df, freq="D")
return ts


@pytest.fixture
def multiple_nan_target_new_category_ts() -> TSDataset:
"""Fixture with several timestamp with NaN target for new category where there were no notna targets yet."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is better to write:

Fixture with segment having multiple NaN targets before first non-NaN target value.

Look at the segment ``A``.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need segment B here?


@pytest.fixture
def multiple_nan_target_old_category_ts() -> TSDataset:
"""Fixture with several timestamp with NaN target for category where there was already a notna target."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is better to write:

Fixture with segment having multiple NaN targets after first non-NaN target value.

Look at the segment ``B``.

Copy link
Collaborator

@d-a-bunin d-a-bunin Nov 6, 2024

Choose a reason for hiding this comment

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

Do we really need segment A here? It almost repeats multiple_nan_target_new_category_ts.

Copy link
Collaborator Author

@egoriyaa egoriyaa Nov 6, 2024

Choose a reason for hiding this comment

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

My motivation was to check each case when there is more that one unique category.
Okey, let't combine these tests. It can be done by adding one more timestamp with "A" category

@github-actions github-actions bot temporarily deployed to pull request November 6, 2024 10:15 Inactive
@egoriyaa egoriyaa requested a review from d-a-bunin November 6, 2024 10:18
@github-actions github-actions bot temporarily deployed to pull request November 6, 2024 12:12 Inactive
@egoriyaa egoriyaa merged commit 4a6e975 into master Nov 6, 2024
17 checks passed
@egoriyaa egoriyaa deleted the issue-490 branch November 6, 2024 13:49
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] MeanEncoderTransform generates wrong values
2 participants