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

Skip to content

Conversation

@lesteve
Copy link
Member

@lesteve lesteve commented Feb 16, 2017

Reference Issue

Fix part of #8098.

What does this implement/fix? Explain your changes.

In the case where both y_pred and y_true are binary it checks that the union of them only has two values otherwise returns 'multiclass' as type.

Any other comments?

I saw #8094 and thought that it was too many different things as once. This is an attempt of making it do one less thing.

if y_type in ["binary", "multiclass"]:
y_true = column_or_1d(y_true)
y_pred = column_or_1d(y_pred)
if y_type == "binary":
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the less invasive fix I could find. This is not super efficient because np.unique has been already called on y_true and y_pred to figure out their type in type_of_target.

y_true_inv = ["b" if i == "a" else "a" for i in y_true]

assert_almost_equal(matthews_corrcoef(y_true, y_true_inv), -1)
y_true_inv2 = label_binarize(y_true, ["a", "b"]) * -1
Copy link
Member Author

Choose a reason for hiding this comment

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

y_true_inv2 is an array of 0 and 1 whereas y_true is an array of 'a' and 'b'. The test was passing just by chance as noted in #8094 (comment).

# And also for any other vector with 0 variance
mcc = assert_warns_message(RuntimeWarning, 'invalid value encountered',
matthews_corrcoef, y_true,
rng.randint(-100, 100) * np.ones(20, dtype=int))
Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to the previous change, y_true is an array of 'a' and 'b' and we are trying to compare it to an array of ints, so something somewhere should tell us that something is wrong.

@codecov
Copy link

codecov bot commented Feb 16, 2017

Codecov Report

Merging #8377 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #8377      +/-   ##
==========================================
+ Coverage   94.75%   94.75%   +<.01%     
==========================================
  Files         342      342              
  Lines       60902    60911       +9     
==========================================
+ Hits        57708    57717       +9     
  Misses       3194     3194
Impacted Files Coverage Δ
sklearn/metrics/classification.py 97.8% <100%> (+0.02%)
sklearn/metrics/tests/test_classification.py 99.57% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b75a81...b71c3b4. Read the comment docs.

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

LGTM. A bug fix changelog entry is deserved.

@lesteve
Copy link
Member Author

lesteve commented Feb 22, 2017

Thanks for the review, I added an entry in the changelog.

@MechCoder MechCoder merged commit 24653e8 into scikit-learn:master Apr 21, 2017
@MechCoder
Copy link
Member

Thanks you.

@lesteve lesteve deleted the fix-check-targets branch April 25, 2017 08:01
@lesteve
Copy link
Member Author

lesteve commented Apr 25, 2017

Thanks for the review @MechCoder !

Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
…and y_pred are both binary but the union is multiclass (scikit-learn#8377)

* Fix _check_targets where y_true and y_pred are both binary

but the union of them is multiclass.

* Add entry in changelog
dmohns pushed a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017
…and y_pred are both binary but the union is multiclass (scikit-learn#8377)

* Fix _check_targets where y_true and y_pred are both binary

but the union of them is multiclass.

* Add entry in changelog
dmohns pushed a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017
…and y_pred are both binary but the union is multiclass (scikit-learn#8377)

* Fix _check_targets where y_true and y_pred are both binary

but the union of them is multiclass.

* Add entry in changelog
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
…and y_pred are both binary but the union is multiclass (scikit-learn#8377)

* Fix _check_targets where y_true and y_pred are both binary

but the union of them is multiclass.

* Add entry in changelog
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
…and y_pred are both binary but the union is multiclass (scikit-learn#8377)

* Fix _check_targets where y_true and y_pred are both binary

but the union of them is multiclass.

* Add entry in changelog
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
…and y_pred are both binary but the union is multiclass (scikit-learn#8377)

* Fix _check_targets where y_true and y_pred are both binary

but the union of them is multiclass.

* Add entry in changelog
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
…and y_pred are both binary but the union is multiclass (scikit-learn#8377)

* Fix _check_targets where y_true and y_pred are both binary

but the union of them is multiclass.

* Add entry in changelog
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