Skip to content

MAINT: make sure warm_start=True is specified - #207

Closed
stsievert wants to merge 4 commits into
dask:masterfrom
stsievert:test-warm-start
Closed

stsievert wants to merge 4 commits into
dask:masterfrom
stsievert:test-warm-start

Conversation

@stsievert

Copy link
Copy Markdown
Member

This PR implements a test to make sure that warm_start=True is specified if the estimator passed to Incremental supports it.

I found that even if warm_start=False, Incremental would reuse results to from previous calls to fit. This PR makes sure that relationship is specified explicitly.

@stsievert stsievert changed the title TST: make sure warm_start=True is specified MAINT: make sure warm_start=True is specified Jun 10, 2018
@mrocklin

Copy link
Copy Markdown
Member

Thank you for identifying and resolving this @stsievert ! It looks like Python 2 tests are failing. I suspect that this can be resolved by adding the following line to the top of the testing file

from future import division

@stsievert

Copy link
Copy Markdown
Member Author

Resolved the Python 2 issue. I've also simplified the tests (by splitting into separate functions), and test this for all estimators (not only SGDClassifier).

@TomAugspurger

Copy link
Copy Markdown
Member

For SGDClassifier, anyway, IIUC, partial_fit uses the previous results, so there won't be any difference.

Do we always want to require warm_start=True?

@stsievert

Copy link
Copy Markdown
Member Author

For SGDClassifier, anyway, IIUC, partial_fit uses the previous results

This is true, and also why I implemented it. I'm am not checking to make sure partial_fit reuses results, and am rather helping to clarify the API to make sure that the user expects Incremental to re-use results. Incremental implicitly assumes warm_start=True, and this PR makes sure it's explicitly specified so the user expects it.

@TomAugspurger

Copy link
Copy Markdown
Member

@stsievert do you think this is still necessary / a good idea?

IMO given that the entire premise of Incremental is incremental training via partial fit, requiring that the underlying estimator be instantiated with warn_start=True is unnecessary.

@stsievert

Copy link
Copy Markdown
Member Author

I'd still like to see this. I'm not worried about warm_start=True being unnecessary. The sklearn introduction says that

Calling fit() more than once will overwrite what was learned by any previous fit()

Calling Incremental.fit will use previous results, which does not follow this convention. This would clarify user expectations, or maybe we should mention this more explicitly in the docs.

@TomAugspurger

TomAugspurger commented Jul 2, 2018 •

Copy link
Copy Markdown
Member

Is the problem with Incremental.fit then? Should calling that "reset" the underlying estimator?

I was playing with some other meta-estimators from scikit-learn. It looks like we may be making a bad promise that the Incremental.estimator is actually the estimator trained.

For sklearn.model_selection.GridSearchCV, the estimator is not actually fit. It's cloned and then the clone is fit. Doing the same for Incremental would nicely solve this warm_start problem, and the problem of state leaking between Incremental.fit calls.

So my proposal is to

  1. Remove the (implicit or explicit) promise that Incremental.estimator is actually fit
  2. Change Incremental.fit to clone before calling fit
  3. Maybe add an estimator_ or fitted_estimator_ attribute that has the actually trained estimator. This is analogous to GridSearchCV.best_estimator_

We'll also need to modify Incremental.partial_fit to be different from Incremental.fit, as it should not clone first.

Does that make any sense at all?

TomAugspurger added a commit to TomAugspurger/dask-ml that referenced this pull request Jul 2, 2018
This changes Incremental.fit to clone before fitting.

Alternative to dask#207
@stsievert

Copy link
Copy Markdown
Member Author
  1. Remove the (implicit or explicit) promise that Incremental.estimator is actually fit
  2. Change Incremental.fit to clone before calling fit
  3. Maybe add an estimator_ or fitted_estimator_ attribute that has the actually trained estimator. This is analogous to GridSearchCV.best_estimator_

This discussion is about Incremental.fit. Either way, Incremental will implement and optimize partial_fit. I see two choices:

  1. have Incremental implement fit.
  2. do not have Incremental implemented fit.

I don't think Incremental.fit should only do one pass over the data. That's a partial fit, and the data is not fitted until convergence like the name implies.

If fit is implemented, I think it should run until convergence because that's what the name implies. I think option 1 will be difficult because sklearn does not expose some property that indicates if the algorithm has converged. I believe the only thing we'd be able to do is make max_iter calls to partial_fit, unless we implement our own convergence functions.

I am leaning towards not implementing fit. Even besides the maintenance cost, I'm not sure the naming even implies we should implement fit. I'm okay leaving the API as is and deprecating fit.

@TomAugspurger

Copy link
Copy Markdown
Member

Given the recent updates to Incremental, is this no longer necessary?

@stsievert stsievert closed this Jul 3, 2018
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.

3 participants