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

Add forecast functions to time series regression pipeline #3742

Merged
merged 8 commits into from
Oct 7, 2022

Conversation

christopherbunn
Copy link
Contributor

@christopherbunn christopherbunn commented Oct 5, 2022

Adds get_forecast_periods() and get_forecast_predictions() to time series regression pipelines.

@christopherbunn christopherbunn force-pushed the TML-5072_predict_on_full_data branch from 69392fc to 1ca503c Compare October 5, 2022 00:53
@codecov
Copy link

codecov bot commented Oct 5, 2022

Codecov Report

Merging #3742 (ddcbc8c) into main (e57c05a) will increase coverage by 0.1%.
The diff coverage is 100.0%.

@@           Coverage Diff           @@
##            main   #3742     +/-   ##
=======================================
+ Coverage   99.7%   99.7%   +0.1%     
=======================================
  Files        341     341             
  Lines      35235   35287     +52     
=======================================
+ Hits       35103   35155     +52     
  Misses       132     132             
Impacted Files Coverage Δ
.../pipelines/time_series_classification_pipelines.py 100.0% <100.0%> (ø)
evalml/pipelines/time_series_pipeline_base.py 100.0% <100.0%> (ø)
...valml/pipelines/time_series_regression_pipeline.py 100.0% <100.0%> (ø)
...peline_tests/test_time_series_baseline_pipeline.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.

@christopherbunn christopherbunn changed the title Add function to forecast on time series regression pipeline Add ability to forecast on time series regression pipeline Oct 5, 2022
@christopherbunn christopherbunn changed the title Add ability to forecast on time series regression pipeline Add forecast functions to time series regression pipeline Oct 5, 2022
@christopherbunn christopherbunn force-pushed the TML-5072_predict_on_full_data branch from 3f4d619 to 2f2a53d Compare October 5, 2022 19:10
Copy link
Contributor Author

@christopherbunn christopherbunn left a comment

Choose a reason for hiding this comment

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

Changes are going to be only for regression pipelines for now. Can move to base class when we revisit for time series classification problems.

X, _, y = ts_data(problem_type=ProblemTypes.TIME_SERIES_REGRESSION)

X_train, y_train = X.iloc[:15], y.iloc[:15]
X_validation = X.iloc[15 : (15 + gap + forecast_horizon)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This holdout dataset has a feature column that is obviously not generated inside of get_forecast_predictions() (i.e. it is multivariate).

)

# Generate numerical index
first_idx = len(X) - 1 if not isinstance(X.index.dtype, int) else X.index[-1]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using this to create a int index that is sequential after X_train

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this so important to have an integer index?

evalml/pipelines/time_series_regression_pipeline.py Outdated Show resolved Hide resolved
forecast_preds = clf.get_forecast_predictions(X=X_train, y=y_train)
X_val_preds = clf.predict(X_validation, X_train=X_train, y_train=y_train)

assert_series_equal(forecast_preds, X_val_preds)
Copy link
Contributor

Choose a reason for hiding this comment

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

Check my understanding here: the only reason these two predictions are the same is because we're using a baseline pipeline, so the extra feature in X doesn't have an impact. For other models though, this isn't going to be the case.

Can we add info/a warning in the function (and docstring, as well as tests) to make users aware that the get_forecast_predictions function only works for univariate problems?

Is that something we're ok with, since we're forecasting?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@eccabay it should work in the multivariate case (when we engineer lagged features) but it doesn't work for KIA features.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These forecasting functions are meant to work for both univariate and multivariate problems. Because we have a forecast horizon and a gap with time series problems, we need to pull from past data. In the case of multivariate problems, we are pulling these features from past rows of X_train after it is transformed through the entire pipeline. For univariate problems, just the periods generated should be fine.

I agree that we should probably use a more complex pipeline that utilizes features though. Updated to include this.

@christopherbunn christopherbunn force-pushed the TML-5072_predict_on_full_data branch from 2d663a4 to 0816cb6 Compare October 6, 2022 19:43
@christopherbunn christopherbunn force-pushed the TML-5072_predict_on_full_data branch from 0816cb6 to 1949ba2 Compare October 6, 2022 19:50
Copy link
Collaborator

@jeremyliweishih jeremyliweishih left a comment

Choose a reason for hiding this comment

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

LGTM - good work!

evalml/pipelines/time_series_regression_pipeline.py Outdated Show resolved Hide resolved
forecast_preds = clf.get_forecast_predictions(X=X_train, y=y_train)
X_val_preds = clf.predict(X_validation, X_train=X_train, y_train=y_train)

assert_series_equal(forecast_preds, X_val_preds)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@eccabay it should work in the multivariate case (when we engineer lagged features) but it doesn't work for KIA features.

Copy link
Contributor

@eccabay eccabay left a comment

Choose a reason for hiding this comment

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

Looks great, thanks Chris!

... "pipeline": {"gap": gap, "max_delay": 1, "forecast_horizon": forecast_horizon, "time_index": "date"}},
... )
>>> pipeline.fit(X, y)
pipeline = TimeSeriesRegressionPipeline(component_graph={'Linear Regressor': ['Linear Regressor', 'X', 'y']}, parameters={'Linear Regressor':{'fit_intercept': True, 'normalize': True, 'n_jobs': -1}, 'pipeline':{'gap': 1, 'max_delay': 1, 'forecast_horizon': 2, 'time_index': 'date'}}, random_seed=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this line

)

# Generate numerical index
first_idx = len(X) - 1 if not isinstance(X.index.dtype, int) else X.index[-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this so important to have an integer index?

@chukarsten chukarsten enabled auto-merge (squash) October 7, 2022 16:09
@chukarsten chukarsten merged commit 77459a6 into main Oct 7, 2022
@chukarsten chukarsten deleted the TML-5072_predict_on_full_data branch October 7, 2022 16:17
@ivanayx ivanayx mentioned this pull request Oct 20, 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.

4 participants