Skip to content

Add target components logic to TSDataset #1153

Merged
merged 9 commits into from
Mar 7, 2023
Merged

Conversation

alex-hse-repository
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 #1142

@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2023

Codecov Report

Merging #1153 (872aeb3) into master (9a29fa8) will increase coverage by 0.53%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #1153      +/-   ##
==========================================
+ Coverage   86.39%   86.93%   +0.53%     
==========================================
  Files         166      177      +11     
  Lines        9513     9847     +334     
==========================================
+ Hits         8219     8560     +341     
+ Misses       1294     1287       -7     
Impacted Files Coverage Δ
etna/datasets/tsdataset.py 92.22% <100.00%> (+0.50%) ⬆️
etna/core/mixins.py 95.23% <0.00%> (-3.41%) ⬇️
...ntal/classification/feature_extraction/__init__.py 100.00% <0.00%> (ø)
etna/experimental/classification/utils.py 100.00% <0.00%> (ø)
etna/experimental/classification/classification.py 96.82% <0.00%> (ø)
etna/experimental/classification/__init__.py 100.00% <0.00%> (ø)
etna/experimental/change_points/__init__.py 100.00% <0.00%> (ø)
etna/experimental/classification/predictability.py 81.25% <0.00%> (ø)
...mental/classification/feature_extraction/weasel.py 97.67% <0.00%> (ø)
...ental/classification/feature_extraction/tsfresh.py 100.00% <0.00%> (ø)
... and 7 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link

github-actions bot commented Mar 6, 2023

@github-actions github-actions bot temporarily deployed to pull request March 6, 2023 08:41 Inactive
@@ -464,6 +467,11 @@ def regressors(self) -> List[str]:
"""
return self._regressors

@property
def target_components(self) -> Optional[List[str]]:
"""Get list of target components. Target components sum up to target."""
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should write that if there are no components, None is returned.

if self._target_components is not None:
raise ValueError("Dataset already contains target components!")

components_names = set(target_components_df.columns.get_level_values("feature"))
Copy link
Contributor

Choose a reason for hiding this comment

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

What if there is duplication in names of components?

@Mr-Geekman
Copy link
Contributor

Should we do something with etna.analysis.plotters.get_residuals?


def test_add_target_components(ts_without_target_components, ts_with_target_components, target_components_df):
ts_without_target_components.add_target_components(target_components_df=target_components_df)
pd.testing.assert_frame_equal(ts_with_target_components.to_pandas(), ts_with_target_components.to_pandas())
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably should be:

pd.testing.assert_frame_equal(ts_without_target_components.to_pandas(), ts_with_target_components.to_pandas()

@@ -481,3 +481,11 @@ def test_get_level_dataset_lower_level_error(simple_hierarchical_ts):
def test_get_level_dataset_with_quantiles(product_level_constant_forecast_w_quantiles, target_level, answer):
forecast = product_level_constant_forecast_w_quantiles
np.testing.assert_array_almost_equal(forecast.get_level_dataset(target_level=target_level).df.values, answer)


def test_get_level_dataset_pass_target_components_to_output(simple_hierarchical_ts):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please explain what is happening here and why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here I test that get_level_dataset pass target_components to the output dataset
It should be done as get_level_dataset creates new dataset with the same columns but different set of segments

Copy link
Contributor

@Mr-Geekman Mr-Geekman left a comment

Choose a reason for hiding this comment

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

Look at comments above.

@alex-hse-repository
Copy link
Collaborator Author

Should we do something with etna.analysis.plotters.get_residuals?

What should we do with it?

@github-actions github-actions bot temporarily deployed to pull request March 7, 2023 07:04 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 7, 2023 07:09 Inactive
for segment in self.segments:
components_names_segment = sorted(target_components_df[segment].columns.get_level_values("feature"))
if components_names != components_names_segment:
raise ValueError("Set of target components differs between segments!")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we write between which segments there is a difference?

Mr-Geekman
Mr-Geekman previously approved these changes Mar 7, 2023
@alex-hse-repository alex-hse-repository enabled auto-merge (squash) March 7, 2023 07:26
@github-actions github-actions bot temporarily deployed to pull request March 7, 2023 07:29 Inactive
@alex-hse-repository alex-hse-repository merged commit 3d76478 into master Mar 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add forecast components handling in TSDataset
3 participants