Repository navigation
Fix/ndcg score - #22710
Fix/ndcg score#22710trinhcon wants to merge 14 commits into
Conversation
deprecation warning for negative ndcg
Micky774
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
| 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 |
| 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) |
There was a problem hiding this comment.
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.
| 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]]) |
| 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) |
There was a problem hiding this comment.
| 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]]) |
| 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) |
There was a problem hiding this comment.
| 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]]) |
| - |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>` |
There was a problem hiding this comment.
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 :)
| - |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 | ||
| """ | ||
|
|
There was a problem hiding this comment.
For a cleaner git blame, try to revert any extraneous line additions/edits.
| else: | ||
| for value in y_true: | ||
| if (value < 0): | ||
| warnings.warn( | ||
| "ndcg_score should not use negative y_true values", | ||
| DeprecationWarning, | ||
| ) |
There was a problem hiding this comment.
The documentation states that y_true : ndarray of shape (n_samples, n_labels) so do we really need this clause?
There was a problem hiding this comment.
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
|
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. |
As an aside, to avoid linting issues check out |
|
@trinhcon Would you still be interested in working on this PR, or can I pick it up? |
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_trueparametercontains any negative values, as this may cause the result not be between
0 and 1.