Skip to content

Forecasters re-factoring: BaseGridSearch, ForecastingGridSearchCV, ForecastingRandomizedSearchCV#1034

Merged
fkiraly merged 24 commits intosktime:mainfrom
GuzalBulatova:gridsearch-re-factor
Jun 30, 2021
Merged

Forecasters re-factoring: BaseGridSearch, ForecastingGridSearchCV, ForecastingRandomizedSearchCV#1034
fkiraly merged 24 commits intosktime:mainfrom
GuzalBulatova:gridsearch-re-factor

Conversation

@GuzalBulatova
Copy link
Copy Markdown
Contributor

@GuzalBulatova GuzalBulatova commented Jun 23, 2021

Reference Issues/PRs

References #955
We need to slowly re-factor all forecasters to be compliant with the new interface (see PR #912). i.e., no overrides of fit etc and descendant classes only implementing core logic, while the BaseForecaster implements check etc logic.

Currently this is running due to various downwards compatibility workarounds, which should be removed once all forecasters are ready (in "no-override" state)

What does this implement/fix? Explain your changes.

  • added self.check_is_fitted() to BaseForecaster's update_predict fn
  • changed fit to private _fit
  • made sure \forecasting\model_selection\tests\test_tune.py pass
  • added _tags: used the (conservative) values from the extension template

Does your contribution introduce a new dependency? If yes, which one?

No

What should a reviewer concentrate their feedback on?

_check_is_fitted (line 170) - is it necessary?

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 24, 2021

I think the test fails because the forecaster does not raise a "not fitted" error when you call update_predict.
Normally, a call self.check_is_fitted() would take care of this.

Now, it would appear this is missing in the base forecaster already. Can you add it there? That should fix this issue.

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 24, 2021

Also, please make sure to update from main.

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 24, 2021

To be more precise:

I think you should try to add the line
self.check_is_fitted() at the start of BaseForecaster's update_predict - that would be my best guess.

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 25, 2021

this looks done - if you think it's done, can you please convert to PR from draft PR and request reviews?
Make sure to update from main first.

@GuzalBulatova
Copy link
Copy Markdown
Contributor Author

Thank you @fkiraly , I've updated and opened it for review.

Copy link
Copy Markdown
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

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

@GuzalBulatova, thanks!

I just noticed a problem: please return the public methods that were not moved "one layer deep" to their original state. This would be get_fitted_params, inverse_transform, score, and evaluate_candidates.

@GuzalBulatova
Copy link
Copy Markdown
Contributor Author

@fkiraly thanks, I've updated the PR. 👍
Should I remove self.check_is_fitted("score") from score method?
In _base.py the method score has commentary "no input checks needed here, they will be performed in predict and loss function".

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 25, 2021

Should I remove self.check_is_fitted("score") from score method?

The mentioned functions should remain entirely unchanged, since we did not change the base classes there.

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 26, 2021

I think there is still a problem with transform and inverse_transform? These should be as they were before.

@GuzalBulatova
Copy link
Copy Markdown
Contributor Author

@fkiraly thank you, I un-did the changes and I think it should all be ready now.

@GuzalBulatova
Copy link
Copy Markdown
Contributor Author

@fkiraly a question about self.check_is_fitted() in cutoff. I took it out, but it's not in base - should we add it to the BaseForecaster or should I return it in BaseGridSearch?

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 27, 2021

@fkiraly a question about self.check_is_fitted() in cutoff. I took it out, but it's not in base - should we add it to the BaseForecaster or should I return it in BaseGridSearch?

Hm, looking at this:

  • it should remain in BaseGridSearch, since it overloads the cutoff with a good reason (mirror the best forecaster)
  • but it should also be added in the BaseForecaster

I.e., it should be in both places in the end. In the description of the PR, make a note where you changed the BaseForecaster.

@GuzalBulatova
Copy link
Copy Markdown
Contributor Author

Hi @fkiraly! I need your advice. After adding fit check in BaseForecaster's cutoff a lot of tests failed. (If add it only to the cutoff in BaseGridSearch all the tests ran fine). As I understand it, there are many estimators that don't call fit. Is there an elegant solution to this? I couldn't figure it out. Thank you!

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 28, 2021

Hi @fkiraly! I need your advice. After adding fit check in BaseForecaster's cutoff a lot of tests failed. (If add it only to the cutoff in BaseGridSearch all the tests ran fine). As I understand it, there are many estimators that don't call fit. Is there an elegant solution to this? I couldn't figure it out. Thank you!

Hm, looks like a number of forecasters check the cutoff when it's not yet fitted.
So I would suggest, remove it from BaseForecaster again, to complete this refactor, and let's discuss separately whether it makes sense that some forecaster access the field itself in fitting, or whether that should be done differently, e.g., via a temporary variable.

Other opinions, @mloning, @aiwalter? I don't think we need to solve the issue in this PR, so let's finish the refactoring without further changes to BaseForecaster and re-visit later.

@fkiraly fkiraly requested a review from ninamiolane June 28, 2021 16:48
@fkiraly fkiraly self-requested a review June 29, 2021 19:27
Copy link
Copy Markdown
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

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

looks good, with the exception that an _update_predict is called.

Currently, this method does not exist in the template, so it should be reverted to update_predict.
I left it that way due to the issues and discussions around #982.

Copy link
Copy Markdown
Contributor

@mloning mloning left a comment

Choose a reason for hiding this comment

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

I think this makes sense now as it is, let's see if the tests pass.

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 30, 2021

wait, why? Why do we need to override almost everything? This doesn't look right.

Copy link
Copy Markdown
Collaborator

@fkiraly fkiraly left a comment

Choose a reason for hiding this comment

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

ok, I've looked at the code.

Indeed it makes sense, since we need to check tags etc in the delegates.

@fkiraly fkiraly merged commit 2730c98 into sktime:main Jun 30, 2021
@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jun 30, 2021

merged, great! Last refactor item done, thanks @GuzalBulatova!

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jul 1, 2021

FYI, some follow-on work is happening in #1088, #1091, #1092

@Lovkush-A
Copy link
Copy Markdown
Collaborator

I just just about to have a look at this, but couldn't find it in the list of PRs. Good stuff for getting this sorted! 😄

@fkiraly
Copy link
Copy Markdown
Collaborator

fkiraly commented Jul 1, 2021

ah, but it's not sorted yet, @Lovkush-A!

Look at #1088, #1091 and #1092.
Seems like @mloning and I disagree on how to proceed.

My fix is in #1091, and @mloning then suggested to do it differently in #1092.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:forecasting forecasting module: forecasting, incl probabilistic and hierarchical forecasting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants