0

I have a multi classification problem which I am trying to solve and the target variable contains genders(male, female). I have used a LabelEncoder from sklearn to implement the one hot encoding. I plotted a confusion matrix, and I got an output containing 0's and 1's instead of classes. How would I be able to get back which class was mapped to which binary number(0,1 etc.)? Any suggestions would be very much helpful.

from sklearn.preprocessing import LabelEncoder

encoder = LabelEncoder()

y = encoder.fit_transform(y)

1 Answers1

0

Just use inverse_transform:

from sklearn import preprocessing

le = preprocessing.LabelEncoder()
data = ['apple', 'orange', 'pinaple', 'orange']
le.fit(data)

encoded = le.transform(data)

>>> [0 1 2 1]

decoded = le.inverse_transform(encoded)

>>> ['apple' 'orange' 'pinaple' 'orange']

Also try to read the documentation before asking, there are a lot of examples: https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html

Sebastian
  • 551
  • 2
  • 8