bind a label to a given encoding with sklearn LabelEncoder

Viewed 31
from sklearn.preprocessing import LabelEncoder
l_labels = ['[PAD]'] + ['NN', 'ADJ', 'PRON'] 
le = LabelEncoder()
le.fit(l_labels)
le.trasform('[PAD]')

>>>> 3

I want the encodind of '[PAD]' to be 0. Is it possible to bind a label to an encoding with LabelEncoder ?

2 Answers

the scikit learn LabelEncoder is sorting the list of element before the transformation one way to encode 'PAD' to be 0 is the change the name of PAD to some thing that will be sorted as first.

l_labels = ['0' + 'PAD'] + ['NN', 'ADJ', 'PRON'] 
le = LabelEncoder()
le.fit(l_labels)
le.transform(['0'+'PAD'])
>> [0]
Related