Skip to content

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

Merged
jeremyliweishih merged 18 commits into
mainfrom
fix_lags
Nov 15, 2022
Merged

Only select lags within FE window dictated by FH and gap#3773
jeremyliweishih merged 18 commits into
mainfrom
fix_lags

Conversation

@jeremyliweishih

Copy link
Copy Markdown
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
Copy Markdown
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.

# 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
Copy Markdown
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.

lagged_features[
f"{col_name}_delay_{self.start_delay + t}"
] = col.shift(self.start_delay + t)
] = col.shift(t)

Copy link
Copy Markdown
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.

lagged_features[
self.target_colname_prefix.format(t + self.start_delay)
] = y.shift(self.start_delay + t)
] = y.shift(t)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

same here.

@ParthivNaresh ParthivNaresh Nov 3, 2022

Copy link
Copy Markdown
Contributor

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

codecov Bot commented Oct 24, 2022

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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?

@thehomebrewnerd thehomebrewnerd left a comment

Copy link
Copy Markdown
Contributor

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!

return_value=pd.DataFrame(),
)
def test_delayed_feature_extractor_maxdelay3_forecasthorizon7_gap1(
def test_delayed_feature_extractor_maxdelay2_forecasthorizon7_gap1(

Copy link
Copy Markdown
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
Copy Markdown
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