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

Skip to content

Conversation

@trinhcon
Copy link
Contributor

@trinhcon trinhcon commented Mar 6, 2022

Reference Issues/PRs

Fixes #17639 .

What does this implement/fix? Explain your changes.

This will cause the function to trigger a warning if the y_true parameter
contains any negative values, as this may cause the result not be between
0 and 1.

Copy link
Contributor

@Micky774 Micky774 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 in this PR! I'm not a core maintainer and you'll still need two of them to review this PR, but I just wanted to offer a few comments :)

y_true : ndarray of shape (n_samples, n_labels)
True targets of multilabel classification, or true scores of entities
to be ranked.
to be ranked. Negative values in y_true may result in an output
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
to be ranked. Negative values in y_true may result in an output
to be ranked. Negative values in `y_true` may result in an output

Comment on lines +1654 to +1655
y_true = np.array([-0.89, -0.53, -0.47, 0.39, 0.56]).reshape(1,-1)
y_score = np.array([0.07,0.31,0.75,0.33,0.27]).reshape(1,-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're trying to organize this into an array of shape (1, 5) then this may be a cleaner way. Similarly for the other tests.

Suggested change
y_true = np.array([-0.89, -0.53, -0.47, 0.39, 0.56]).reshape(1,-1)
y_score = np.array([0.07,0.31,0.75,0.33,0.27]).reshape(1,-1)
y_true = np.array([[-0.89, -0.53, -0.47, 0.39, 0.56]])
y_score = np.array([[0.07,0.31,0.75,0.33,0.27]])

Comment on lines +1661 to +1662
y_true = np.array([-0.89, -0.53, -0.47, 0.39, 0.56]).reshape(1,-1)
y_score = np.array([0.07,0.31,0.75,0.33,0.27]).reshape(1,-1)
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
y_true = np.array([-0.89, -0.53, -0.47, 0.39, 0.56]).reshape(1,-1)
y_score = np.array([0.07,0.31,0.75,0.33,0.27]).reshape(1,-1)
y_true = np.array([[-0.89, -0.53, -0.47, 0.39, 0.56]])
y_score = np.array([[0.07,0.31,0.75,0.33,0.27]])

Comment on lines +1666 to +1667
y_true = np.array([0.11, 0.47, 0.53, 1.39, 1.56]).reshape(1,-1)
y_score = np.array([1.07, 1.31, 1.75, 1.33, 1.27]).reshape(1,-1)
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
y_true = np.array([0.11, 0.47, 0.53, 1.39, 1.56]).reshape(1,-1)
y_score = np.array([1.07, 1.31, 1.75, 1.33, 1.27]).reshape(1,-1)
y_true = np.array([[0.11, 0.47, 0.53, 1.39, 1.56]])
y_score = np.array([[1.07, 1.31, 1.75, 1.33, 1.27]])

Comment on lines +613 to +616
- |Fix| :func:`metrics.ndcg_score` will now trigger a warning when the y_true
value contains a negative value. It will allow the user to still use negative
values, but the result may not be between 0 and 1.
:pr:`22710` by :user:`Conroy Trinh <trinhcon>`
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to use `backticks` for parameters like y_true. This should probably also mention the deprecation of negative values for y_true. I made a minor wording edit as well, but feel free to rephrase as you see fit :)

Suggested change
- |Fix| :func:`metrics.ndcg_score` will now trigger a warning when the y_true
value contains a negative value. It will allow the user to still use negative
values, but the result may not be between 0 and 1.
:pr:`22710` by :user:`Conroy Trinh <trinhcon>`
- |Fix| :func:`metrics.ndcg_score` will now trigger a warning when `y_true`
contains a negative value. The user may still use negative
values, but the result may not be between 0 and 1. Begins deprecation
of negative values in `y_true`.
:pr:`22710` by :user:`Conroy Trinh <trinhcon>`

... scores, k=1, ignore_ties=True)
0.5
"""

Copy link
Contributor

Choose a reason for hiding this comment

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

For a cleaner git blame, try to revert any extraneous line additions/edits.

Comment on lines +1634 to +1640
else:
for value in y_true:
if (value < 0):
warnings.warn(
"ndcg_score should not use negative y_true values",
DeprecationWarning,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation states that y_true : ndarray of shape (n_samples, n_labels) so do we really need this clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This clause was for one of the tests that from it seemed did not use numpy arrays, but the regular one. I found that removing the else clause, causes these kinds of tests to fail. Unless I am misunderstanding the issue, it is necessary for some of tests to pass

@trinhcon
Copy link
Contributor Author

trinhcon commented Mar 6, 2022

To clean up some of the suggested changes and try to fix what seems to be a linting error with newlines in the test files, I'll make another commit.

I am working on a team which also fixes another issue and I am thinking of making a PR for them together.

@Micky774
Copy link
Contributor

Micky774 commented Mar 6, 2022

To clean up some of the suggested changes and try to fix what seems to be a linting error with newlines in the test files, I'll make another commit.

As an aside, to avoid linting issues check out pre-commit. Scikit-learn is configured to automatically run linting/reformatting programs via pre-commit every time you commit. It saves a huge amount of effort :)

@Micky774
Copy link
Contributor

Micky774 commented Apr 3, 2022

@trinhcon Would you still be interested in working on this PR, or can I pick it up?

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.

ndcg_score fails for negative scores

3 participants