Label Encoding

Learn how to encode categorical features with the label encoding method.

What is label encoding?

We all know that the machine learning algorithm can only deal with numerical features. However, in most scenarios, categorical features are prevalent. For example, a person’s gender, address, product type, weather, and so on are categorical features. To ensure the machine learning algorithm can use this information (features or fields), we need to transform these categorical features into numerical features. Label encoding is one of the methods used for this transformation.

In short, label encoding is simply converting each value of a column to a number like the image shown below.

Notice: The encoding operation must be performed simultaneously on both the train and test datasets. Otherwise, it may cause inconsistencies in the encoding of the same data in different datasets.

Get hands-on with 1400+ tech skills courses.