Skip to content

[MRG] Fix label_ranking_average_precision_score: sample_weighting isn't applied to items with zero true labels #13412#13447

Merged
NicolasHug merged 5 commits intoscikit-learn:masterfrom
dpwe:lrap_weighting_zero_labels
Apr 20, 2019
Merged

[MRG] Fix label_ranking_average_precision_score: sample_weighting isn't applied to items with zero true labels #13412#13447
NicolasHug merged 5 commits intoscikit-learn:masterfrom
dpwe:lrap_weighting_zero_labels

Conversation

@dpwe
Copy link
Copy Markdown
Contributor

@dpwe dpwe commented Mar 14, 2019

Fixes #13412

What does this implement/fix? Explain your changes.

sklearn.metrics.label_ranking_average_precision_score supports a sample_weight argument to allow different contributions of individual trial samples. However, in the case where certain samples had degenerate labels (all true or none true), the special case logic that gave these samples a precision of 1.0 failed to apply the sample_weights. This is now corrected, with tests that exercise sample_weight without degenerate labels (a test that passed before the code was modified), and with degenerate labels (a test that failed until this change was applied).

Any other comments?

Copy link
Copy Markdown
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.

Thanks for the pr!!

Please add an entry to the change log at doc/whats_new/v0.21.rst. Like the other entries there, please reference this pull request with :issue: and credit yourself (and other contributors if applicable) with :user:

n_classes, n_samples, random_state)


def test_lrap_sample_weighting():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is tested by test_common.py unless I'm much mistaken. However it seems we don't generate any samples without labels there, perhaps intentionally since I think some metrics might not handle it

assert_almost_equal(
label_ranking_average_precision_score(y_true, y_score,
sample_weight=sample_weight),
np.sum(sample_weight * samplewise_lraps)/np.sum(sample_weight))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Spaces around / please

@dpwe
Copy link
Copy Markdown
Contributor Author

dpwe commented Mar 18, 2019

Thanks for the feedback; all fixed I believe. PTAL.

@jnothman jnothman added the Bug label Mar 19, 2019
@jnothman jnothman added this to the 0.21 milestone Mar 19, 2019
Copy link
Copy Markdown
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

nitpick but LGTM


- |Fix| :func:`metrics.label_ranking_average_precision_score` was returning
incorrect values where some samples had degenerate labels and `sample_weight`
was used.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems that you're saying that sample_weight shouldn't be used.

How about:

Fixed a bug in [...] where sample_weight wasn't taken into account for samples with degenerate labels

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ping @dpwe ;) could you please address this so we can merge?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay. I made the change you suggested.

@NicolasHug NicolasHug merged commit 572e43d into scikit-learn:master Apr 20, 2019
@NicolasHug
Copy link
Copy Markdown
Member

Thanks @dpwe!

jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Apr 25, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

label_ranking_average_precision_score: sample_weighting isn't applied to items with zero true labels

3 participants