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

Only select lags within FE window dictated by FH and gap #3773

Merged
merged 18 commits into from
Nov 15, 2022
Merged

Conversation

jeremyliweishih
Copy link
Collaborator

Fixes #3770

def _find_significant_lags(y, conf_level, max_delay):
all_lags = np.arange(max_delay + 1)
def _find_significant_lags(y, conf_level, start_delay, max_delay):
all_lags = np.arange(start_delay, start_delay + max_delay + 1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only filter by lags that start in the feature engineering window.

@@ -173,7 +174,9 @@ def _find_significant_lags(y, conf_level, max_delay):
set(index[significant]).intersection(peaks).union(first_significant_10)
)
# If no lags are significant get the first lag
significant_lags = sorted(significant_lags.intersection(all_lags)) or [1]
significant_lags = sorted(significant_lags.intersection(all_lags)) or [
start_delay,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

default to using the start of the feature engineering window.

@@ -246,7 +249,7 @@ def _compute_delays(self, X_ww, y):
feature_name = f"{col_name}_delay_{self.start_delay + t}"
lagged_features[
f"{col_name}_delay_{self.start_delay + t}"
] = col.shift(self.start_delay + t)
] = col.shift(t)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lags already have the start delay baked in since we're only selecting lags that start from the feature engineering window.

@@ -256,7 +259,7 @@ def _compute_delays(self, X_ww, y):
for t in self.statistically_significant_lags:
lagged_features[
self.target_colname_prefix.format(t + self.start_delay)
] = y.shift(self.start_delay + t)
] = y.shift(t)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same here.

Copy link
Contributor

@ParthivNaresh ParthivNaresh Nov 3, 2022

Choose a reason for hiding this comment

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

If the start_delay is 11 and the significant lag is 11, then this comes out to a format of 21 (because 11 + 11 - 1). So we'd be shifting by 11 and the feature would be called target_delay_21? Shouldn't the shift and the column name suffix come out to the same number?

@codecov
Copy link

codecov bot commented Oct 24, 2022

Codecov Report

Merging #3773 (5a5959b) into main (8cf0cda) will not change coverage.
The diff coverage is 100.0%.

@@          Coverage Diff          @@
##            main   #3773   +/-   ##
=====================================
  Coverage   99.7%   99.7%           
=====================================
  Files        344     344           
  Lines      36123   36123           
=====================================
  Hits       35986   35986           
  Misses       137     137           
Impacted Files Coverage Δ
...ansformers/preprocessing/time_series_featurizer.py 100.0% <100.0%> (ø)
...sts/component_tests/test_time_series_featurizer.py 99.7% <100.0%> (ø)
...s/prediction_explanations_tests/test_explainers.py 100.0% <100.0%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

lagged_features[
f"{col_name}_delay_{self.start_delay + t}"
] = col.shift(self.start_delay + t)
f"{col_name}_delay_{self.start_delay + t - 1}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

-1 since the lag is inclusive of the start delay.

@jeremyliweishih jeremyliweishih marked this pull request as ready for review November 10, 2022 16:41
# Check that the computed features to be explained aren't NaN.
for exp_idx in range(len(exp["explanations"])):
assert not np.isnan(
assert not pd.isnull(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ParthivNaresh do you know why we need to do this conversion?

Copy link
Contributor

@thehomebrewnerd thehomebrewnerd left a comment

Choose a reason for hiding this comment

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

Did some testing with this updated function and the results I got seemed to always fall within the bounds of the feature engineering window. Looks good to me!

def test_delayed_feature_extractor_maxdelay3_forecasthorizon7_gap1(
def test_delayed_feature_extractor_maxdelay2_forecasthorizon7_gap1(
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the reasoning behind changing this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IIRC just to match the lags on the dataset

@jeremyliweishih jeremyliweishih enabled auto-merge (squash) November 15, 2022 18:47
@jeremyliweishih jeremyliweishih merged commit 6585c4a into main Nov 15, 2022
@jeremyliweishih jeremyliweishih deleted the fix_lags branch November 15, 2022 18:55
@chukarsten chukarsten mentioned this pull request Nov 23, 2022
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.

TimeSeriesFeaturizer doesn't appear to use correct significant lags in most cases
4 participants