Skip to content
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

average_precision for binary classification #36

Open
amineremache opened this issue Jun 16, 2020 · 0 comments
Open

average_precision for binary classification #36

amineremache opened this issue Jun 16, 2020 · 0 comments

Comments

@amineremache
Copy link

Hello,

The function test.py/average_precision uses label_binarize from sklearn.preprocessing, and if you read the documentation you can see that it explicitly says :
Shape will be [n_samples, 1] for binary problems.

So you get this error:

image

Because since the output of this function will be used to calculate the average precision, the target and predictions must have the same shape ( Nx2 ).

Here is a "quick" solution that I don't like a lot (basically creating a dummy class), so if anyone could give a better one that would be good:

def average_precision(prob_np, target_np):
num_class = prob_np.shape[1]
if num_class == 2:
num_class += 1
label = label_binarize(target_np, classes=list(range(num_class)))
with np.errstate(divide='ignore', invalid='ignore'):
return average_precision_score(label, prob_np, None)

And also, if you think that I am mistaken, please let me know, feedback is always welcomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant