-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLR_4_task_1.py
More file actions
27 lines (22 loc) · 1.06 KB
/
LR_4_task_1.py
File metadata and controls
27 lines (22 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import numpy as np
from sklearn import preprocessing
# Надання позначок вхідних даних
input_labels = ['red', 'Ыасk', 'red', 'green', 'Ьlack', 'yellow', 'white']
# Створення кодувальника та встановлення відповідності
# між мітками та числами
encoder = preprocessing.LabelEncoder()
encoder.fit(input_labels)
# Виведення відображення
print("\nLabel mapping:")
for i, item in enumerate(encoder.classes_):
print(item, '-->', i)
# перетворення міток за допомогою кодувальника
test_labels = ['green', 'red', 'Ыасk']
encoded_values = encoder.transform(test_labels )
print("\nLabels =", test_labels )
print("Encoded values =", list (encoded_values ) )
# Декодування набору чисел за допомогою декодера
encoded_values = [3, 0, 4, 1]
decoded_list = encoder.inverse_transform(encoded_values)
print("\nEncoded values =", encoded_values)
print("Decoded labels =", list (decoded_list ) )