Label Encoding
We will be using .LabelEncoder() from sklearn library to convert categorical data to numerical data. We will use function fit_transform() in the process.
Syntax :
fit_transform(y)
Parameters :
- y : array-like of shape (n_samples). Target Values.
Returns : array-like of shape (n_samples) .Encoded labels.
How to convert categorical string data into numeric in Python?
The datasets have both numerical and categorical features. Categorical features refer to string data types and can be easily understood by human beings. However, machines cannot interpret the categorical data directly. Therefore, the categorical data must be converted into numerical data for further processing.
There are many ways to convert categorical data into numerical data. Here in this article, we’ll be discussing the two most used methods namely :
- Dummy Variable Encoding
- Label Encoding
In both the Methods we are using the same data, the link to the dataset is here
Contact Us