from sklearn import preprocessing

label_encoder = preprocessing.LabelEncoder()
input_classes = ['audi', 'ford', 'audi', 'toyota', 'ford', 'bmw']
label_encoder.fit(input_classes)
print("\nClass mapping:")
for i, item in enumerate(label_encoder.classes_):
    print(item, '-->', i)
#OUT:Class mapping:
#audi --> 0
#bmw --> 1
#ford --> 2
#toyota --> 3

labels = ['toyota', 'ford', 'audi']
encoded_labels = label_encoder.transform(labels)
print("\nLabels =",labels)
print("Encoder labels =",list(encoded_labels))

# 数字反转回单词
encoder_labels = [2, 1, 0, 3, 1]
decoder_labels = label_encoder.inverse_transform(encoder_labels)
print("\nEncoder labels =", encoder_labels)
print("Decoder labels =", list(decoder_labels))


8116807c5b739b4d49c511a742c7f5dbedb659e3
<mask token>

<mask token>
label_encoder.fit(input_classes)
print('\nClass mapping:')
for i, item in enumerate(label_encoder.classes_):
    print(item, '-->', i)
<mask token>
print('\nLabels =', labels)
print('Encoder labels =', list(encoded_labels))
<mask token>
print("""
Encoder labels =""", encoder_labels)
print('Decoder labels =', list(decoder_labels))

<mask token>
label_encoder = preprocessing.LabelEncoder()
input_classes = ['audi', 'ford', 'audi', 'toyota', 'ford', 'bmw']
label_encoder.fit(input_classes)
print('\nClass mapping:')
for i, item in enumerate(label_encoder.classes_):
    print(item, '-->', i)
labels = ['toyota', 'ford', 'audi']
encoded_labels = label_encoder.transform(labels)
print('\nLabels =', labels)
print('Encoder labels =', list(encoded_labels))
encoder_labels = [2, 1, 0, 3, 1]
decoder_labels = label_encoder.inverse_transform(encoder_labels)
print("""
Encoder labels =""", encoder_labels)
print('Decoder labels =', list(decoder_labels))

from sklearn import preprocessing
label_encoder = preprocessing.LabelEncoder()
input_classes = ['audi', 'ford', 'audi', 'toyota', 'ford', 'bmw']
label_encoder.fit(input_classes)
print('\nClass mapping:')
for i, item in enumerate(label_encoder.classes_):
    print(item, '-->', i)
labels = ['toyota', 'ford', 'audi']
encoded_labels = label_encoder.transform(labels)
print('\nLabels =', labels)
print('Encoder labels =', list(encoded_labels))
encoder_labels = [2, 1, 0, 3, 1]
decoder_labels = label_encoder.inverse_transform(encoder_labels)
print("""
Encoder labels =""", encoder_labels)
print('Decoder labels =', list(decoder_labels))

from sklearn import preprocessing

label_encoder = preprocessing.LabelEncoder()
input_classes = ['audi', 'ford', 'audi', 'toyota', 'ford', 'bmw']
label_encoder.fit(input_classes)
print("\nClass mapping:")
for i, item in enumerate(label_encoder.classes_):
    print(item, '-->', i)
#OUT:Class mapping:
#audi --> 0
#bmw --> 1
#ford --> 2
#toyota --> 3

labels = ['toyota', 'ford', 'audi']
encoded_labels = label_encoder.transform(labels)
print("\nLabels =",labels)
print("Encoder labels =",list(encoded_labels))

# 数字反转回单词
encoder_labels = [2, 1, 0, 3, 1]
decoder_labels = label_encoder.inverse_transform(encoder_labels)
print("\nEncoder labels =", encoder_labels)
print("Decoder labels =", list(decoder_labels))

