Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Note on inappropriate usage of cross_val_predict #9883
Conversation
shaz13
referenced this pull request
Oct 8, 2017
Closed
Note about appropriate and inappropriate uses of cross_val_predict #9827
+folds and grouped in different ways on computation in comparison to :func:`cross_val_predict`. | ||
+Thus, any metric score on :func:`cross_val_predict` is not equivalent to the | ||
+result of :func:`cross_val_score`. The function :func:`cross_val_predict` should | ||
+only be used to evaluate a classifier and is not an appropriate measure of |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
jnothman
Oct 8, 2017
Owner
I think I'd should not be used to evaluate a classifier, but perhaps to do some diagnostic analysis or visualisation of predictions...
jnothman
Oct 8, 2017
Owner
I think I'd should not be used to evaluate a classifier, but perhaps to do some diagnostic analysis or visualisation of predictions...
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
shaz13
Oct 8, 2017
Contributor
Oh, In that case, a small query. In the original user guide it suggests so --
at http://scikit-learn.org/stable/modules/cross_validation.html
Shall I remove that line of phrase or just in the notes?
shaz13
Oct 8, 2017
Contributor
Oh, In that case, a small query. In the original user guide it suggests so --
at http://scikit-learn.org/stable/modules/cross_validation.html
Shall I remove that line of phrase or just in the notes?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
yes, IMO that example should be removed
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
ping @gaelvaroquaux who has written on this subject
|
@jnothman Sure. I will replace the example with a Note defining the appropriate usage. Thanks! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
Also, I think the case of blended estimators is worth mentioning. |
Pushed a new commit. Please take a look @jnothman. |
+================================================ | ||
+The function :func:`cross_val_score` takes an average of over cross-validation | ||
+folds and is grouped in different ways on computation in comparison to :func:`cross_val_predict`. | ||
+Any metric score on :func:`cross_val_predict` is not equivalent to the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
jnothman
Oct 9, 2017
Owner
That's not true. if all folds are of equal size, and the metric is a mean of sample-wise scores, then they will be identical.
jnothman
Oct 9, 2017
Owner
That's not true. if all folds are of equal size, and the metric is a mean of sample-wise scores, then they will be identical.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
+Note on inappropriate usage of cross_val_predict | ||
+================================================ | ||
+The function :func:`cross_val_score` takes an average of over cross-validation | ||
+folds and is grouped in different ways on computation in comparison to :func:`cross_val_predict`. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
jnothman
Oct 9, 2017
Owner
I find this vague and unclear. What does "is grouped in different ways on computation" mean?
jnothman
Oct 9, 2017
Owner
I find this vague and unclear. What does "is grouped in different ways on computation" mean?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
shaz13
Oct 9, 2017
Contributor
I was reframing the words of this deleted note
"- -Note that the result of this computation may be slightly different from those
-obtained using :func:cross_val_score
as the elements are grouped in different
-ways."
Is this not true too ?
shaz13
Oct 9, 2017
Contributor
I was reframing the words of this deleted note
"- -Note that the result of this computation may be slightly different from those
-obtained using :func:cross_val_score
as the elements are grouped in different
-ways."
Is this not true too ?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
+not an appropriate measure of generalisation error. | ||
+ | ||
+The valid use of :func:`cross_val_predict` is for visualization of | ||
+training set predictions and model blending techniques. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
jnothman
Oct 9, 2017
Owner
I think this is again vague. Try to be more specific. Look at where cross_val_predict
is currently used in the library, and try to explain it in your own words.
jnothman
Oct 9, 2017
Owner
I think this is again vague. Try to be more specific. Look at where cross_val_predict
is currently used in the library, and try to explain it in your own words.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
shaz13
Oct 9, 2017
Contributor
@jnothman Please let me know if this looks good. I have quoted the note in the comment. If everything looks good will make a push.
The result of :func:
cross_val_predict
may be slightly different from those
obtained using :func:cross_val_score as the elements are grouped in different
ways. The function :func:cross_val_score
takes an average of over cross-validation
folds where as :func:cross_val_predict
just returns the labels without taking
average of cross-validation folds. Thus, the function :func:cross_val_predict
is not an appropriate measure of generalisation error.The :func:
cross_val_predict
is appropriate for visualisation of training set predictions
with y_train values to study the model on train set. Additionally, it can be used
in model blending techniques to get ensembled predictions.
@jnothman Please let me know if this looks good. I have quoted the note in the comment. If everything looks good will make a push.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
jnothman
Oct 9, 2017
Owner
where as :func:cross_val_predict just returns the labels without taking
average of cross-validation folds.
Well it returns the labels (or probabilities, etc) from several distinct models undistinguished.
Well it returns the labels (or probabilities, etc) from several distinct models undistinguished. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
jnothman
Oct 9, 2017
Owner
Maybe "Additionally, it can be used when predictions of one supervised estimator are used to train another estimator in ensemble methods" would be clearer.
Maybe "Additionally, it can be used when predictions of one supervised estimator are used to train another estimator in ensemble methods" would be clearer. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
shaz13
Oct 9, 2017
Contributor
Thanks @jnothman for the corrections. How does this revised note look?
The result of :func:cross_val_predict may be slightly different from those
obtained using :func:cross_val_score as the elements are grouped in different
ways. The function :func:cross_val_score takes an average of over cross-validation
folds where as :func:cross_val_predict just returns the labels (or probabilities, etc) from several distinct models undistinguished without taking average of cross-validation folds. Thus, the function :func:cross_val_predict is not an appropriate measure of generalisation error.The :func:cross_val_predict is appropriate for visualisation of training set predictions with y_train values to study the model on train set. Additionally, it can be used when predictions of one supervised estimator are used to train another estimator in ensemble methods.
Thanks @jnothman for the corrections. How does this revised note look?
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
jnothman
Oct 9, 2017
Owner
I think this could still be written better (in shorter sentences), but it's
acceptable.
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
shaz13
Oct 10, 2017
Contributor
Thanks for the reveiw @jnothman. I have made it shorter. How does this look?
The result of :func:cross_val_predict may be different from those
obtained using :func:cross_val_score as the elements are grouped in different ways. The function :func:cross_val_score takes an average of over cross-validation folds where as :func:cross_val_predict simply returns the labels (or probabilities) from several distinct models undistinguished. Thus, :func:cross_val_predict is not an appropriate measure of generalisation error.The :func:cross_val_predict is appropriate for;
- Visualization of training set predictions to study the model on train set.
- Model blending: When predictions of one supervised estimator are used to train another estimator in ensemble methods.
Thanks for the reveiw @jnothman. I have made it shorter. How does this look?
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
jnothman
Oct 11, 2017
Owner
this is definitely getting better but it's easier to comment on the diff
than in a comment thread.
I'm not happy with the use of "training set" because all of the predictions
are on held-out data within each iteration of cv.
|
Pushed a new commit @jnothman. Please take a look! |
- >>> predicted = cross_val_predict(clf, iris.data, iris.target, cv=10) | ||
- >>> metrics.accuracy_score(iris.target, predicted) # doctest: +ELLIPSIS | ||
- 0.973... | ||
+Note on inappropriate usage of cross_val_predict |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
lesteve
Oct 13, 2017
Member
Rather than a new section, you should use the warning sphinx directive. Look at other places in the doc where it is used. Either git grep '\.\. warning'
or search for .. warning ::
in https://raw.githubusercontent.com/scikit-learn/scikit-learn/7dffa20363d095320ede354edf66f8b6123ba121/doc/developers/contributing.rst.
lesteve
Oct 13, 2017
Member
Rather than a new section, you should use the warning sphinx directive. Look at other places in the doc where it is used. Either git grep '\.\. warning'
or search for .. warning ::
in https://raw.githubusercontent.com/scikit-learn/scikit-learn/7dffa20363d095320ede354edf66f8b6123ba121/doc/developers/contributing.rst.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
+ | ||
+The :func:`cross_val_predict` is appropriate for: | ||
+ - Visualization of predictions obtained from different models. | ||
+ - Model blending: When predictions of one supervised estimator are used to train another estimator in ensemble methods. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
lesteve
Oct 13, 2017
Member
This line is quite long, find a good editor that limits automatically the width of the line, e.g. to something like 80. More generally, try to respect the convention you can see from the file you are editing.
lesteve
Oct 13, 2017
Member
This line is quite long, find a good editor that limits automatically the width of the line, e.g. to something like 80. More generally, try to respect the convention you can see from the file you are editing.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
@lesteve Made changes as suggested. Please take a look |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
See rendering at http://scikit-learn.org/circle/?14255/_changed.html |
- 0.973... | ||
+.. warning:: Note on inappropriate usage of cross_val_predict | ||
+ | ||
+The result of :func:`cross_val_predict` may be different from those |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
jnothman
Oct 15, 2017
Owner
@GaelVaroquaux does this agree with your position on uses of
cross_val_predict vs cross_val_score?
|
@jnothman Ping. Is this PR good to go? |
jnothman
approved these changes
Jan 9, 2018
I'm happy enough with this, but a second opinion wouldn't hurt...
qinhanmin2014
approved these changes
Mar 8, 2018
LGTM, I pushed some minor changes, will merge after checking the result from Circle
qinhanmin2014
merged commit 2eb731b
into
scikit-learn:master
Mar 8, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
Thanks @shaz13 :) |
shaz13 commentedOct 8, 2017
Fixes #9827