Created
July 10, 2021 07:13
-
-
Save MathiasGruber/21d95598dc5b45cdaf65cbd5d624fc30 to your computer and use it in GitHub Desktop.
Conversion from ordinal predictions to class labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def prediction2label(pred: np.ndarray): | |
"""Convert ordinal predictions to class labels, e.g. | |
[0.9, 0.1, 0.1, 0.1] -> 0 | |
[0.9, 0.9, 0.1, 0.1] -> 1 | |
[0.9, 0.9, 0.9, 0.1] -> 2 | |
etc. | |
""" | |
return (pred > 0.5).cumprod(axis=1).sum(axis=1) - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment