Skip to content

Altering precision_recall_fscore_support docstring #3670

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

Closed
wants to merge 1 commit into from

Conversation

nathanathan
Copy link

If the labels are unsorted and precision_recall_fscore_support is used with multilabel classifications it will raise an exception. E.g.:

sklearn.metrics.precision_recall_fscore_support(
    [(1,2)],
    [(3,4)],
    labels=[4, 1, 2, 3]
)

raises

/usr/local/lib/python2.7/dist-packages/sklearn/metrics/classification.pyc in precision_recall_fscore_support(y_true, y_pred, beta, labels, pos_label, average, warn_for, sample_weight)
    945     elif label_order is not None:
    946         indices = np.searchsorted(labels, label_order)
--> 947         precision = precision[indices]
    948         recall = recall[indices]
    949         f_score = f_score[indices]

IndexError: index 4 is out of bounds for size 4

Also, AFAICT the labels do not need to be integers.

If the labels are unsorted and precision_recall_fscore_support is used with multilabel classifications it will raise an exception. E.g.:
```
sklearn.metrics.precision_recall_fscore_support(
    [(1,2)],
    [(3,4)],
    labels=[4, 1, 2, 3]
)
```
raises
```
/usr/local/lib/python2.7/dist-packages/sklearn/metrics/classification.pyc in precision_recall_fscore_support(y_true, y_pred, beta, labels, pos_label, average, warn_for, sample_weight)
    945     elif label_order is not None:
    946         indices = np.searchsorted(labels, label_order)
--> 947         precision = precision[indices]
    948         recall = recall[indices]
    949         f_score = f_score[indices]

IndexError: index 4 is out of bounds for size 4
```
Also, AFAICT the labels do not need to be integers.
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 484dacf on nathanathan:patch-1 into 12f63da on scikit-learn:master.

@jnothman
Copy link
Member

I agree it's broken (and probably created the bug myself), but I think it should be properly fixed.

@jnothman
Copy link
Member

In any case, it shouldn't fail silently for some unsorted setting of labels

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

Successfully merging this pull request may close these issues.

4 participants