Inverse Process of Label Binarisation in Python

Viewed 3091

I have performed a label binarisation for multiclass classification and it is working fine:

y_test
1
3
4
2
0

from sklearn.preprocessing import label_binarize

y_test_binarize = label_binarize(y_test, classes=[0, 1, 2, 3, 4])
y_test_binarize

0   1   0   0   0
0   0   0   1   0
0   0   0   0   1
0   0   1   0   0
1   0   0   0   0

Next, I would like to do an inverse process to get y_test from y_test_binarize variable.

Are there any predefined methods?

3 Answers

Using argmax functions of numpy:

np.argmax(y_test_binarized, axis=1)
Related