I label encoded my categorical data into numerical data using label encoder
data['Resi'] = LabelEncoder().fit_transform(data['Resi'])
But I when I try to find how they are mapped internally using
list(LabelEncoder.inverse_transform(data['Resi']))
I am getting below error
TypeError Traceback (most recent call last)
<ipython-input-67-419ab6db89e2> in <module>()
----> 1 list(LabelEncoder.inverse_transform(data['Resi']))TypeError: inverse_transform() missing 1 required positional argument: 'y'
How to fix this
Sample data
Resi
IP
IP
IP
IP
IP
IE
IP
IP
IP
IP
IP
IPD
IE
IE
IP
IE
IP
IP
IP
You can check label encoding:
>>> from sklearn import preprocessing
>>> le = preprocessing.LabelEncoder()
>>> le.fit([1, 2, 2, 6])
LabelEncoder()
>>> le.classes_
array([1, 2, 6])
>>> le.transform([1, 1, 2, 6])
array([0, 0, 1, 2])
>>> le.inverse_transform([0, 0, 1, 2])
array([1, 1, 2, 6])
And for your solution:
from sklearn.preprocessing import LabelEncoderle = LabelEncoder().fit(data['Resi'])
data['Resi'] = le.transform(data['Resi'])
print (data.tail())Resi
14 1
15 0
16 1
17 1
18 1L = list(le.inverse_transform(data['Resi']))
print (L)
['IP', 'IP', 'IP', 'IP', 'IP', 'IE', 'IP', 'IP', 'IP', 'IP', 'IP', 'IPD', 'IE', 'IE', 'IP', 'IE', 'IP', 'IP', 'IP']
EDIT:
d = dict(zip(le.classes_, le.transform(le.classes_)))
print (d)
{'IE': 0, 'IPD': 2, 'IP': 1}