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

Is there an easy way to obtain a confusion matrix? #49

Closed
goerch opened this issue May 7, 2020 · 2 comments
Closed

Is there an easy way to obtain a confusion matrix? #49

goerch opened this issue May 7, 2020 · 2 comments

Comments

@goerch
Copy link

goerch commented May 7, 2020

I'm trying

    confusion_matrix(y_test, y_pred)

with sklearn's method, but am getting the error message

ValueError: You appear to be using a legacy multi-label data representation. Sequence of sequences are no longer supported; use a binary array or sparse matrix instead - the MultiLabelBinarizer transformer can convert to this format.
@soerenetler
Copy link

Hi @goerch, I assume your y_true and y_pred are nested lists, right? For the confusion matrix function you have to flatten them first. Does that help?
Have a great weekend,
Sören

@goerch
Copy link
Author

goerch commented May 9, 2020

Thanks @soerenetler, excellent advice. I didn't bother to read the source before, but now I have

from sklearn_crfsuite.utils import flatten

mcm = multilabel_confusion_matrix(flatten(y_test), flatten(y_pred))

which works as intended.

@goerch goerch closed this as completed May 9, 2020
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

2 participants