-
Notifications
You must be signed in to change notification settings - Fork 80
Make trend transforms work with NaNs #456
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## master #456 +/- ##
==========================================
- Coverage 87.98% 87.97% -0.01%
==========================================
Files 115 115
Lines 5435 5440 +5
==========================================
+ Hits 4782 4786 +4
- Misses 653 654 +1
Continue to review full report at Codecov.
|
martins0n
approved these changes
Jan 18, 2022
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 seems ok
But something like this not working anyway and we should think about it
import pandas as pd
from etna import pipeline
from etna.datasets.tsdataset import TSDataset
from etna.pipeline import Pipeline
from etna.metrics import SMAPE
from etna.transforms import TrendTransform
from etna.models.sarimax import SARIMAXModel
from sklearn.linear_model import LinearRegression
import numpy as np
from etna.transforms.missing_values import imputation
def example_df():
df1 = pd.DataFrame()
df1["timestamp"] = pd.date_range(start="2020-01-01", end="2020-02-01", freq="H")
df1["segment"] = "segment_1"
df1["target"] = np.arange(len(df1))
#+ 2 * np.random.normal(size=len(df1)
df2 = pd.DataFrame()
df2["timestamp"] = pd.date_range(start="2020-01-01", end="2020-02-01", freq="H")
df2["segment"] = "segment_2"
df2["target"] = np.sqrt(np.arange(len(df2)) + 2 * np.cos(np.arange(len(df2))))
return pd.concat([df1, df2], ignore_index=True)
def df_with_nans_in_tails(example_df):
df = TSDataset.to_dataset(example_df)
df.loc[:4, pd.IndexSlice["segment_1", "target"]] = None
df.loc[-3:, pd.IndexSlice["segment_1", "target"]] = None
return df
example_df = example_df()
df_with_nans_in_tails = df_with_nans_in_tails(example_df)
from etna.datasets import *
from etna.models import *
from etna.transforms import *
from etna.pipeline import Pipeline
pipeline = Pipeline(model=NaiveModel(), transforms=[LinearTrendTransform("target"), TimeSeriesImputerTransform()], horizon=5)
pipeline.fit(TSDataset(df_with_nans_in_tails, freq="1H"))
print(pipeline.forecast())
series = df.loc[df[self.in_column].first_valid_index() :, self.in_column] | ||
series = df.loc[df[self.in_column].first_valid_index() : df[self.in_column].last_valid_index(), self.in_column] | ||
if series.isnull().values.any(): | ||
raise ValueError("The input column contains NaNs in the middle of the series! Try to use the imputer.") |
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.
Before PR. Did it work with nulls in middle of TSDataset?
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
IMPORTANT: Please do not create a Pull Request without creating an issue first.
Before submitting (must do checklist)
Type of Change
Proposed Changes
Related Issue
Closing issues
closes #417