Adds hinge loss function algorithm#10628
Adds hinge loss function algorithm#10628tianyizheng02 merged 13 commits intoTheAlgorithms:masterfrom PoojanSmart:master
Conversation
| import numpy as np | ||
|
|
||
|
|
||
| def hinge_loss(y_true: np.ndarray, pred: np.ndarray) -> float: |
There was a problem hiding this comment.
| def hinge_loss(y_true: np.ndarray, pred: np.ndarray) -> float: | |
| def hinge_loss(y_true: np.ndarray, y_pred: np.ndarray) -> float: |
Please rename for consistency
|
#10637 (comment) also applies here. |
I can combine all loss function into single file, then you can review. We will do further modularization if required based on loss function category. Let me know your thoughts.. |
|
I will allow @tianyizheng02 to review this PR because he has already had several good suggestions. On this repo, if you |
|
|
||
| # Raise value error when y_true (encoded labels) have any other values | ||
| # than -1 and 1 | ||
| if np.array_equal(np.sort(np.unique(y_true)), np.array([-1, 1])) is False: |
There was a problem hiding this comment.
| if np.array_equal(np.sort(np.unique(y_true)), np.array([-1, 1])) is False: | |
| if np.any((y_true != 1) & (y_true != -1)): |
This should do the same thing (check if any entry is neither 1 or -1)
Describe your change:
Checklist: