Python Machine Learing Label Encoding

Python Machine Learning Label Encoding

Python Machine Learning Label Encoding – When we do classification, there will be alot of Labels that we are going to deal with that
these Labels can be in the form of words, numbers or something else, so when we are using Sklearn it expects numbers. so if the data are numbers then there is no problem, we can use
them directly to start training. But this is not usually the case.
In the real world, labels are in the form of words, because words are human readable. We
label our training data with words so that the mapping can be tracked. To convert word
labels into numbers, we need to use a label encoder. Label encoding refers to the process of
transforming the word labels into numerical form. This enables the algorithms to operate on
our data.

You can watch my previous article on Python Machine Learning

 

1: Python Machine Learning Introduction

2: Python Machine Learning Open Source Libraries

3: Python Machine Learning Preprocessing The Data

 

So this the code for the Python Machine Learning Label Encoding

 

These line of code are our sample data

 

And this is the mapping between words and numbers

 

This is the result

Python Machine Learning Label Encoding The Data
Python Machine Learning Label Encoding The Data

 

Let’s encode a set of randomly ordered labels to see how it performs:

 

Add these lines of codes to above code

This the result

Machine Learning Label Encoding
Machine Learning Label Encoding

 

So now we are going to decode a random set of numbers:

 

Add these lines of codes

 

This is the result

Python Machine Learning Decoded Values
Python Machine Learning Decoded Value

 

Complete code

 

(Visited 553 times, 2 visits today)
Share via
Copy link
Powered by Social Snap