-
Notifications
You must be signed in to change notification settings - Fork 80
ScalerTransform: micro and macro mode #61
Conversation
mode: | ||
"macro" or "per-segment", way to transform features over segments. | ||
If "macro", transforms features globally, gluing the corresponding ones for all segments. | ||
If "per-segment", transforms features for each segment separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be we should add Raises block here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have Raises block in the similar case in Metric
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
etna/transforms/scalers.py
Outdated
Raises | ||
------ | ||
ValueError: | ||
if incorrect strategy given |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strategy -> mode
etna/transforms/scalers.py
Outdated
Raises | ||
------ | ||
ValueError: | ||
if incorrect strategy given |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strategy -> mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Codecov Report
@@ Coverage Diff @@
## master #61 +/- ##
==========================================
+ Coverage 90.33% 90.48% +0.15%
==========================================
Files 45 45
Lines 1976 2008 +32
==========================================
+ Hits 1785 1817 +32
Misses 191 191
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add the same for power transforms.
etna/transforms/scalers.py
Outdated
@@ -23,6 +24,7 @@ def __init__( | |||
inplace: bool = True, | |||
with_mean: bool = True, | |||
with_std: bool = True, | |||
mode: str = TransformMode.per_segment, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type TransformMode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we pass the sting, not the TransformMode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> from etna.transforms.sklearn import TransformMode
>>> TransformMode.per_segment
<TransformMode.per_segment: 'per-segment'>
>>> type(TransformMode.per_segment)
<enum 'TransformMode'>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be "per-segment" instead of TransformMode.per_segment)
etna/transforms/sklearn.py
Outdated
macro = "macro" | ||
per_segment = "per-segment" | ||
|
||
@classmethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should remove this.
Maybe we will add this with mixin later for every enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
segments = sorted(set(df.columns.get_level_values("segment"))) | ||
x = df.loc[:, pd.IndexSlice[:, self.in_column]] | ||
x = pd.concat([x[segment] for segment in segments]).values | ||
return x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x
- is numpy array, isnt it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
etna/transforms/sklearn.py
Outdated
x = self._reshape(df) | ||
transformed = self.transformer.inverse_transform(X=x) | ||
transformed = self._inverse_reshape(df, transformed) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not great finalize without else statement -- this is kind of pattern matching and we should raise Exception or doing something for other possible cases.
The probablity of self.mode not equal to something from enum is mostly equal to zero. But it can be, for example you change mode by hand in tests and you could pass everything.
So we should raise ValueError in else
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* Add micro and macro mode for ScalerTransform * Add macro/micro mode for power transformers Co-authored-by: a.p.chikov <a.p.chikov@macbook-a.p.chikov>
* Add cap and floor to prophet regressor columns * Refactor if-block * Add changelog (#60) * Create CHANGELOG.md * Add version 1.0.0 * add unreleased changes * LinearTrendTransform bug fix (#49) * Fix tsdataset getitem method (#25) * fix tsdataset getitem method * fix style * add test for all indexes * fix imports * add Nan info * fix typo Co-authored-by: an.alekseev <an.alekseev@tinkoff.ru> * ScalerTransform: micro and macro mode (#61) * Add micro and macro mode for ScalerTransform * Add macro/micro mode for power transformers Co-authored-by: a.p.chikov <a.p.chikov@macbook-a.p.chikov> * Revert "Add cap and floor to prophet regressor columns" This reverts commit 8c60bba. * Add processing regressor_cap and regressor_floor features, add notes in documentation about it * Update changelog * Fix missing add regressor * Fix wrong code, edit test * Reformat code Co-authored-by: Andrey Alekseev <ilekseev@gmail.com> Co-authored-by: alex-hse-repository <55380696+alex-hse-repository@users.noreply.github.com> Co-authored-by: an.alekseev <an.alekseev@tinkoff.ru> Co-authored-by: a.p.chikov <a.p.chikov@macbook-a.p.chikov>
IMPORTANT: Please do not create a Pull Request without creating an issue first.
Before submitting (checklist)
make lint
(poetry install -E style
).pytest tests/
?Type of Change
Proposed Changes
Related Issue
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Closing issues
Put
closes #XXXX
in your comment to auto-close the issue that your PR fixes (if such).