Skip to content

Confusion matrix derived metrics #15522

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

Conversation

samskruthireddy
Copy link

Reference Issues/PRs

Adding Fall-out, Miss rate, specificity as metrics #5516

What does this implement/fix? Explain your changes.

Implemented a function which returns fpr, tpr, fnr, tnr.

Any other comments?

Implementation of seperate functions for each metric which calls this function is still pending.
Co-authored by @ddhar1 @samskruthireddy

@jnothman
Copy link
Member

jnothman commented Nov 4, 2019

This requires adding to test_common.py and specific behaviours tested in test_classification.py

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

I am unsure about the naming. I think that we need to use the full name (e.g. true_positive_rate) instead of acronym (e.g. tpr).

@@ -2173,7 +2376,8 @@ def log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None,
y_true : array-like or label indicator matrix
Ground truth (correct) labels for n_samples samples.

y_pred : array-like of float, shape = (n_samples, n_classes) or (n_samples,)
y_pred : array-like of float, shape = (n_samples, n_classes)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
y_pred : array-like of float, shape = (n_samples, n_classes)
y_pred : array-like of float, shape = (n_samples, n_classes) \

@@ -2173,7 +2376,8 @@ def log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None,
y_true : array-like or label indicator matrix
Ground truth (correct) labels for n_samples samples.

y_pred : array-like of float, shape = (n_samples, n_classes) or (n_samples,)
y_pred : array-like of float, shape = (n_samples, n_classes)
or (n_samples,)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
or (n_samples,)
or (n_samples,)

Copy link
Contributor

@haochunchang haochunchang left a comment

Choose a reason for hiding this comment

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

Good work! @samskruthireddy
Is this PR work in progress?
I would like to work on this if this PR is stalled.

tpr : float (if average is not None) or array of float, shape =\
[n_unique_labels]

fpr : float (if average is not None) or array of float, , shape =\
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a small extra comma :)

Suggested change
fpr : float (if average is not None) or array of float, , shape =\
fpr : float (if average is not None) or array of float, shape =\

Examples
--------
>>> import numpy as np
>>> from sklearn.metrics import precision_recall_fscore_support
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a dependency of this function?
Since the following examples did not use this function.

Suggested change
>>> from sklearn.metrics import precision_recall_fscore_support

Comment on lines +1716 to +1726
if average == 'weighted':
weights = pos_sum
if weights.sum() == 0:
zero_division_value = 0.0 if zero_division in ["warn", 0] else 1.0
# precision is zero_division if there are no positive predictions
# recall is zero_division if there are no positive labels
# fscore is zero_division if all labels AND predictions are
# negative
return (zero_division_value if pred_sum.sum() == 0 else 0,
zero_division_value,
zero_division_value if pred_sum.sum() == 0 else 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here seems to only return 3 values.

Comment on lines +1600 to +1601
alters 'macro' to account for label imbalance; it can result in an
F-score that is not between precision and recall.
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this function does not return F-score.

Suggested change
alters 'macro' to account for label imbalance; it can result in an
F-score that is not between precision and recall.
alters 'macro' to account for label imbalance.

Comment on lines +1556 to +1558
If ``pos_label is None`` and in binary classification, this function
returns the average precision, recall and F-measure if ``average``
is one of ``'micro'``, ``'macro'``, ``'weighted'`` or ``'samples'``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
If ``pos_label is None`` and in binary classification, this function
returns the average precision, recall and F-measure if ``average``
is one of ``'micro'``, ``'macro'``, ``'weighted'`` or ``'samples'``.
If ``pos_label is None`` and in binary classification, this function
returns the true positive rate, false positive rate, true negative rate
and false negative rate if ``average`` is one of ``'micro'``, ``'macro'``,
``'weighted'`` or ``'samples'``.

@lucyleeow
Copy link
Member

@haochunchang it's been marked as 'stalled' so I think you can take over

haochunchang added a commit to haochunchang/scikit-learn that referenced this pull request May 18, 2020
Modify documentation and add deprecation of position arg.
haochunchang added a commit to haochunchang/scikit-learn that referenced this pull request May 18, 2020
Modify doc and add deprecation to position arg.
haochunchang added a commit to haochunchang/scikit-learn that referenced this pull request May 18, 2020
Modify doc and add deprecation to position arg.
@haochunchang
Copy link
Contributor

I have opened a new PR #17265 to take over this stalled PR.
Anyone interested is welcome :)

@albertvillanova
Copy link
Contributor

@cmarmo, maybe the label "help wanted" should be removed from this PR. Thanks.

Base automatically changed from master to main January 22, 2021 10:51
@glemaitre
Copy link
Member

closing in favor of #19556

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.

7 participants