-
Notifications
You must be signed in to change notification settings - Fork 91
Refactor time series pipeline code via time series pipeline base class #2649
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0c2d932
init
angela97lin a7be699
more cleanup
angela97lin e77c77b
Merge branch 'main' into 2614_refactor_time_series
angela97lin 6ed7292
more cleanup
angela97lin c641ea6
Merge branch '2614_refactor_time_series' of github.com:alteryx/evalml…
angela97lin 97dc6ef
more cleanup
angela97lin 5280f36
some more cleanup and release notes
angela97lin f7a2898
clean up inheritance and docstring
angela97lin c07ee07
linting
angela97lin c1589af
remove inheritance of regressionpipeline
angela97lin 344a135
Merge branch 'main' into 2614_refactor_time_series
angela97lin 21357d7
Merge branch 'main' into 2614_refactor_time_series
chukarsten cedae47
add to breaking change
angela97lin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import pandas as pd | ||
|
|
||
| from evalml.pipelines import PipelineBase | ||
| from evalml.pipelines.pipeline_meta import TimeSeriesPipelineBaseMeta | ||
| from evalml.utils import drop_rows_with_nans, infer_feature_types | ||
|
|
||
|
|
||
| class TimeSeriesPipelineBase(PipelineBase, metaclass=TimeSeriesPipelineBaseMeta): | ||
|
|
||
| """Pipeline base class for time series problems. | ||
|
|
||
| Arguments: | ||
| component_graph (list or dict): List of components in order. Accepts strings or ComponentBase subclasses in the list. | ||
| Note that when duplicate components are specified in a list, the duplicate component names will be modified with the | ||
| component's index in the list. For example, the component graph | ||
| [Imputer, One Hot Encoder, Imputer, Logistic Regression Classifier] will have names | ||
| ["Imputer", "One Hot Encoder", "Imputer_2", "Logistic Regression Classifier"] | ||
| parameters (dict): Dictionary with component names as keys and dictionary of that component's parameters as values. | ||
| An empty dictionary {} implies using all default values for component parameters. Pipeline-level | ||
| parameters such as date_index, gap, and max_delay must be specified with the "pipeline" key. For example: | ||
| Pipeline(parameters={"pipeline": {"date_index": "Date", "max_delay": 4, "gap": 2}}). | ||
| random_seed (int): Seed for the random number generator. Defaults to 0. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| component_graph, | ||
| parameters=None, | ||
| custom_name=None, | ||
| random_seed=0, | ||
| ): | ||
| if not parameters or "pipeline" not in parameters: | ||
| raise ValueError( | ||
| "date_index, gap, and max_delay parameters cannot be omitted from the parameters dict. " | ||
| "Please specify them as a dictionary with the key 'pipeline'." | ||
| ) | ||
| pipeline_params = parameters["pipeline"] | ||
| self.date_index = pipeline_params["date_index"] | ||
| self.gap = pipeline_params["gap"] | ||
| self.max_delay = pipeline_params["max_delay"] | ||
| super().__init__( | ||
| component_graph, | ||
| custom_name=custom_name, | ||
| parameters=parameters, | ||
| random_seed=random_seed, | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def _convert_to_woodwork(X, y): | ||
| if X is None: | ||
| X = pd.DataFrame() | ||
| X = infer_feature_types(X) | ||
| y = infer_feature_types(y) | ||
| return X, y | ||
|
|
||
| def fit(self, X, y): | ||
| """Fit a time series pipeline. | ||
|
|
||
| Arguments: | ||
| X (pd.DataFrame or np.ndarray): The input training data of shape [n_samples, n_features]. | ||
| y (pd.Series, np.ndarray): The target training targets of length [n_samples]. | ||
|
|
||
| Returns: | ||
| self | ||
| """ | ||
| X, y = self._convert_to_woodwork(X, y) | ||
| self._fit(X, y) | ||
| return self | ||
|
|
||
| def _fit(self, X, y): | ||
| self.input_target_name = y.name | ||
| X_t = self.component_graph.fit_features(X, y) | ||
| y_shifted = y.shift(-self.gap) | ||
| X_t, y_shifted = drop_rows_with_nans(X_t, y_shifted) | ||
| self.estimator.fit(X_t, y_shifted) | ||
| self.input_feature_names = self.component_graph.input_feature_names | ||
|
|
||
| def _estimator_predict(self, features, y): | ||
| """Get estimator predictions. | ||
|
|
||
| This helper passes y as an argument if needed by the estimator. | ||
| """ | ||
| y_arg = None | ||
| if self.estimator.predict_uses_y: | ||
| y_arg = y | ||
| return self.estimator.predict(features, y=y_arg) |
This file contains hidden or 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
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.
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.
Can you please mark that
TimeSeriesRegressionPipelinedoes not inherit fromRegressionPipelineas a breaking change?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.
sure thing 😁