Last active
April 2, 2018 15:43
-
-
Save andreaschandra/c31aba3d49506a1abe449b3475558a65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
label_kategori = ['senin', 'selasa', 'rabu', 'kamis', 'jumat', 'sabtu', 'minggu'] | |
encoder = preprocessing.LabelEncoder() | |
encoder.fit(label_kategori) | |
print("\nLabel mapping:") | |
for i, item in enumerate(encoder.classes_): | |
print(item, '>', i) | |
output: | |
Label mapping: | |
jumat > 0 | |
kamis > 1 | |
minggu > 2 | |
rabu > 3 | |
sabtu > 4 | |
selasa > 5 | |
senin > 6 | |
# Encode list menggunakan encoder sebelumnya | |
test_labels = ['senin', 'kamis', 'jumat'] | |
encoded_values = encoder.transform(test_labels) | |
print("Labels =", test_labels) | |
print("Encoded values =", list(encoded_values)) | |
Labels = ['senin', 'kamis', 'jumat'] | |
Encoded values = [6, 1, 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment