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

Skip to content

[MRG+2] Added sample weight support to confusion matrix. #4001

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

Closed
wants to merge 4 commits into from
Closed

[MRG+2] Added sample weight support to confusion matrix. #4001

wants to merge 4 commits into from

Conversation

DanielSidhion
Copy link

Added a sample_weight parameter inside confusion_matrix which
will be used to build the confusion matrix. If not present, it
will default to np.ones() of size equal to the number of samples.
Tests were created in test_classification.py instead of
test_common.py.

@DanielSidhion
Copy link
Author

Implementation for #3450. Any feedback is appreciated.


cm = confusion_matrix(y_true, y_pred, sample_weight=weights)

assert_array_almost_equal(cm, [[4.1, 0.8, 0.1],
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 not have this hard-coded. More precisely, we can use:

assert_array_almost_equal(cm,
                          .1 * confusion_matrix(y_true[:25], y_pred[:25]) + 
                          .2 * confusion_matrix(y_true[25:50], y_pred[25:50]) +
                          .3 * confusion_matrix(y_true[50:], y_pred[50:]))

Copy link
Author

Choose a reason for hiding this comment

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

That's definitely better. I was influenced by the tests around it which had hard-coded values as well. Thank you for the feedback! Will push a commit shortly.

@MechCoder
Copy link
Member

Are you still here? can you rebase?

@DanielSidhion
Copy link
Author

Hi! Just got the notification. Will rebase in 48h, as I'm currently unable to do that.

@MechCoder
Copy link
Member

Sure. !

Bernardo Vecchia Stein added 2 commits January 18, 2016 03:26
Added a sample_weight parameter inside confusion_matrix which
will be used to build the confusion matrix. If not present, it
will default to np.ones() of size equal to the number of samples.
Tests were created in test_classification.py instead of
test_common.py.
Removed hard-coded result matrix for something better.
@DanielSidhion
Copy link
Author

Should be ok now. If there's anything else you need, just let me know!

# confusion_matrix with sample_weight is in
# test_classification.py
"hamming_loss",
"matthews_corrcoef_score",
Copy link
Member

Choose a reason for hiding this comment

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

you can remove the "hamming loss" and "matthews_corrocef_score". They were supported recently

@MechCoder
Copy link
Member

Just that minor comment. Will merge after that

@MechCoder MechCoder changed the title Added sample weight support to confusion matrix. [MRG+2] Added sample weight support to confusion matrix. Jan 18, 2016
@DanielSidhion
Copy link
Author

Sorry about that! Please let me know of anything else needed. Thanks!

sample_weight = np.ones(y_true.shape[0], dtype=np.int)
else:
sample_weight = np.asarray(sample_weight)

Copy link
Member

Choose a reason for hiding this comment

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

nitpick: can you add a check here, to see if sample_weight is the same size as y_true and y_pred using check_consistent_length?

Copy link
Author

Choose a reason for hiding this comment

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

@MechCoder sure, seems like a good addition. I added the check after the highlighted code just to make sure that in the future, if some part of the previous code changes, the check still catches any future problems.

It would be good to have some tests against this behavior, but I'm a little short on time in the following weeks, so it's probably better to merge this and later I'll add another PR to improve the tests. What do you think?

@MechCoder
Copy link
Member

Merged as 01b5b7b after doing a cosmit, an error to check for inconsistent length and updating whatsnew. Sorry for the year long wait @DanielSidhion !

@MechCoder MechCoder closed this Jan 19, 2016
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