Label encoding
When performing classification, we usually deal with lots of labels. These labels can be in the form of words, numbers, or something else. Many machine learning algorithms require numbers as input. So, if they are already numbers, they can be directly used for training. But this is not always the case.
Labels are normally words, because words can be understood by humans. Training data is labeled with words so that the mapping can be tracked. To convert word labels into numbers, a label encoder can be used. Label encoding refers to the process of transforming word labels into numbers. This enables the algorithms to be able to process the data. Let's look at an example:
Create a new Python file and import the following packages:
import numpy as np
from sklearn import preprocessing
Define some sample labels:
# Sample input labels
input_labels = ['red', 'black', 'red', 'green', 'black', &apos...