-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG] Adds support for sample weight in hinge loss #3788
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
4c0b04b
to
129733f
Compare
Can anyone please review this? cc @MechCoder @jnothman @arjoly |
@@ -1184,6 +1184,32 @@ def test_hinge_loss_multiclass_invariance_lists(): | |||
dummy_hinge_loss) | |||
|
|||
|
|||
def test_hinge_loss_multiclass_sample_weight(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have reason to believe the invariance test is insufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Invariance test is sufficient here. I will remove this in next commit.
The implementation looks good to me, but I'm not sure the specialised test adds anything. |
@@ -1492,4 +1495,7 @@ def hinge_loss(y_true, pred_decision, labels=None): | |||
losses = 1 - margin | |||
# The hinge_loss doesn't penalize good enough predictions. | |||
losses[losses <= 0] = 0 | |||
return np.mean(losses) | |||
if sample_weight is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary. np.average
already handles the case where weights=None
Referencing #3450 |
Need one more reviewer. @MechCoder Can you please have a look at this? |
This looks good, except for the fact that you should validate the first dimension of the pred_decision and sample_weights. This can be done just be adding |
+1 when addressing @MechCoder's comment. |
Merged as d21d6dd . Thanks. |
Thanks everyone for the reviews. :-) |
This is dependent on #3607. I will uncomment the added lines after it's merge in main tree.