Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MRG allow empty grid in ParameterGrid #2082

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 2 commits into from
Jun 22, 2013

Conversation

larsmans
Copy link
Member

Fixes #2048.

@larsmans
Copy link
Member Author

Demo:

>>> from sklearn.svm import LinearSVC
>>> clf = LinearSVC()
>>> from sklearn.datasets import load_digits
>>> digits = load_digits()
>>> from sklearn.grid_search import GridSearchCV
>>> GridSearchCV(clf, {}, cv=2).fit(digits.data, digits.target)
GridSearchCV(cv=2,
       estimator=LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True,
     intercept_scaling=1, loss='l2', multi_class='ovr', penalty='l2',
     random_state=None, tol=0.0001, verbose=0),
       fit_params={}, iid=True, loss_func=None, n_jobs=1, param_grid={},
       pre_dispatch='2*n_jobs', refit=True, score_func=None, scoring=None,
       verbose=0)

That's exactly the default settings for LinearSVC:

>>> LinearSVC()
LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True,
     intercept_scaling=1, loss='l2', multi_class='ovr', penalty='l2',
     random_state=None, tol=0.0001, verbose=0)

@jnothman
Copy link
Member

Hmm. While I've had a case that would benefit from this (only because the extension of ParameterGrid to handle lists of grids, together with #1769), I think this is a bit unintuitive. Is it better to use None for this than change the semantics of dict-qua-grid?

@larsmans
Copy link
Member Author

IMHO, it hardly changes the semantics. A grid like {"C": [1, 10]} searches C but with the default value for all other parameters. It seems natural to me that an empty grid would mean the default value for all parameters. I would find an explicit None rather unintuitive.

@jnothman
Copy link
Member

I see your point. The number of candidates is less intuitive, but if from {'C': [1, 10], 'gamma': [1, 2]} to {'C': [1, 10]} you divide by 2, divide by two again from there to {}!

In any case, please add documentation and fix/test for __len__. (I also note test_parameter_grid doesn't cover the list of dicts case.)

@jnothman
Copy link
Member

And please refer to it as a "special case" rather than a "corner case", even if you find it an intuitive special case.

@larsmans
Copy link
Member Author

There. I added a commit that finally explains the behavior of ParameterGrid on lists.

@jnothman
Copy link
Member

LGTM, then. But I'd like another opinion on whether the semantics are reasonable. @amueller? @ogrisel?

@larsmans
Copy link
Member Author

Ping @mblondel.

@mblondel
Copy link
Member

I think this comment could also be removed:
https://github.com/larsmans/scikit-learn/blob/cb4b7e9740d0dbf0d470fd7d5055125b07a167bb/sklearn/grid_search.py#L82

Other than that, LGTM

@larsmans
Copy link
Member Author

I figured it would be smart to explain what the example does, but I can remove it.

Thanks to @mblondel for explaining this functionality.
larsmans added a commit that referenced this pull request Jun 22, 2013
MRG allow empty grid in ParameterGrid
@larsmans larsmans merged commit a7d34ca into scikit-learn:master Jun 22, 2013
@larsmans larsmans deleted the empty-parameter-grid branch June 22, 2013 19:17
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.

allow GridSearchCV to work with params={} or cv=1
3 participants