8000 [MRG+1] New text for the ValueError that is thrown by _check_param_grid method by b0noI · Pull Request #7216 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+1] New text for the ValueError that is thrown by _check_param_grid method #7216

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 9 commits into from
Aug 31, 2016

Conversation

b0noI
Copy link
Contributor
@b0noI b0noI commented Aug 20, 2016

Reference Issue

N/A

What does this implement/fix? Explain your changes.

ValueError that is thrown by _check_param_grid method now includes parameters name when values of a parameter have incorrect type.

Old ValueError:
ValueError: Parameter values should be a list.

New ValueError:
ValueError: Parameter(key1) values should be a non-empty list.

Any other comments?

p.items() - creates a new list that includes tuples from the original dict on the Python2.x, however amount of a params should not be big, so it should not be a problem. On a Python 3.x items() crates iterator.

2 tests are broken:
sklearn.feature_extraction.tests.test_image.test_connect_regions ... FAIL
sklearn.feature_extraction.tests.test_image.test_connect_regions_with_grid ... FAIL
they have been broken before my commit. No new breakage is introduced by the commit itself.

…rameters name when values of a parameter have incorrect type.

Old ValueError:
ValueError: Parameter values should be a list.

New ValueError:
ValueError: Parameter(key1) values should be a non-empty list.
@jnothman
Copy link
Member
jnothman commented Aug 20, 2016

I don't mind something like this, but sklean.grid_search is deprecated. Please edit sklearn.model_selection._search

b0noI added 2 commits August 20, 2016 13:32
…rameters name when values of a parameter have incorrect type.

Old ValueError:
ValueError: Parameter values should be a list.

New ValueError:
ValueError: Parameter(key1) values should be a non-empty list.
@b0noI
Copy link
Contributor Author
b0noI commented Aug 20, 2016

jnothman@ done, both places have been updated. Thank you for the feedback, I didn't know about deprecation.

PS: As soon as this one is merged, I will prepare PR that fixes support of range() in the method, since in Python3.X range does not return a list anymore. As a result some of the code is not working correctly after switching from Python2.X to 3.X

@jnothman
Copy link
Member

PS: As soon as this one is merged, I will prepare PR that fixes support of range() in the method, since in Python3.X range does not return a list anymore. As a result some of the code is not working correctly after switching from Python2.X to 3.X

I'm not sure what you're referring to... Can you link to the misuse of range??


if len(v) == 0:
raise ValueError("Parameter values should be a non-empty "
"list.")
raise ValueError("Parameter({0}) values should be a non-empty "
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather "Parameter ({0}) value should be ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@b0noI
Copy link
Contributor Author
b0noI commented Aug 23, 2016

I'm not sure what you're referring to... Can you link to the misuse of range??

Simplified version of the logic from _check_param_grid method:
`v = range(0, 100)

check = [isinstance(v, k) for k in (list, tuple)]
print(True in check)
print(type(v))`

results on Python 2.X:
True
<type 'list'>

results on Python 3.X:
False
<class 'range'>

So some of the code is not working after migration to Python 3 =(

@jnothman
Copy link
Member

Yes, that does appear to be a separate bug, and is obviously not tested. We could make use of collections.Sequence.

@b0noI
Copy link
Contributor Author
b0noI commented Aug 23, 2016

jnothman@ yep, I can implement a tests for the usage of collections.Sequence. Probably will start with filing a bug =)

PS: I updated the text of the Errors

if isinstance(v, np.ndarray) and v.ndim > 1:
raise ValueError("Parameter array should be one-dimensional.")

check = [isinstance(v, k) for k in (list, tuple, np.ndarray)]
if True not in check:
raise ValueError("Parameter values should be a list.")
raise ValueError("Parameter ({0}) value should be a list."
Copy link
Member

Choose a reason for hiding this comment

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

I have a hard time parsing this sentence. Currently when searching over parameter alpha, it says something like

Parameter (alpha) value should be a list.

That seems not very intuitive. Each parameter value for alpha should be a float.
Maybe " Parameter values for parameter {} need to be a sequence". ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

amueller@: your text look better, indeed. Thank you. PS: pull-request has been updated.

Old value: Parameter ({0}) value should be a list.
New value: Parameter values for parameter ({}) need to be a sequence.
@b0noI
Copy link
Contributor Author
b0noI commented Aug 26, 2016

jnothman@ anything else you want me to change in the request?

@jnothman
Copy link
Member

Well, I know for one thing that {} isn't supported in Python 2.6, which we still support and test. This line is clearly not covered by our current tests. Could you add a test for it?

@b0noI
Copy link
Contributor Author
b0noI commented Aug 28, 2016

jnothman@ thank you! I did't know about the {} and Python 2.6. Error text has been updated. Plus I have added two tests that are covering cases when ValueError are thrown.

ValueError,
"Parameter values for parameter (C) need to be a sequence.",
GridSearchCV,
None,
Copy link
Member

Choose a reason for hiding this comment

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

I think you should provide an estimator here. The test case is unnecessarily pathological.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if isinstance(v, np.ndarray) and v.ndim > 1:
raise ValueError("Parameter array should be one-dimensional.")

check = [isinstance(v, k) for k in (list, tuple, np.ndarray)]
if True not in check:
raise ValueError("Parameter values should be a list.")
raise ValueError("Parameter values for parameter ({0}) need to "
Copy link
Member

Choose a reason for hiding this comment

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

PEP8 line length

Copy link
Member

Choose a reason for hiding this comment

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

These should be strictly <80 characters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jnothman
Copy link
Member

LGTM. We usually require a second reviewer before merging.

@jnothman jnothman changed the title [MRG] New text for the ValueError that is thrown by _check_param_grid method [MRG+1] New text for the ValueError that is thrown by _check_param_grid method Aug 31, 2016
@ogrisel
Copy link
Member
ogrisel commented Aug 31, 2016

LGTM as well. Merging, thanks a lot @b0noI!

@ogrisel ogrisel merged commit db56cf4 into scikit-learn:master Aug 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0