{"id":18980,"date":"2023-11-08T10:17:38","date_gmt":"2023-11-08T04:47:38","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/"},"modified":"2024-12-18T20:31:11","modified_gmt":"2024-12-18T15:01:11","slug":"label-encoding-in-python","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/","title":{"rendered":"Label Encoding in Python"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction\"><strong>Introduction <\/strong><\/h2>\n\n\n\n<p>Label encoding is a technique used in machine learning and data analysis to convert categorical variables into numerical format. It is particularly useful when working with algorithms that require numerical input, as most machine learning models can only operate on numerical data. In this explanation, we'll explore how label encoding works and how to implement it in Python.<\/p>\n\n\n\n<p>Let's consider a simple example with a dataset containing information about different types of fruits, where the \"Fruit\" column has categorical values such as \"Apple,\" \"Orange,\" and \"Banana.\" Label encoding assigns a unique numerical label to each distinct category, transforming the categorical data into numerical representation.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p>To perform label encoding in Python, we can use the scikit-learn library, which provides a range of preprocessing utilities, including the LabelEncoder class. Here's a step-by-step guide:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Import the necessary libraries:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">pythonCopy code<code>from sklearn.preprocessing import LabelEncoder\n<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Create an instance of the LabelEncoder class:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">pythonCopy code<code>label_encoder = LabelEncoder()\n<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Fit the label encoder to the categorical data:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">pythonCopy code<code>label_encoder.fit(categorical_data)\n<\/code><\/pre>\n\n\n\n<p>Here, <code>categorical_data<\/code> refers to the column or array containing the categorical values you want to encode.<\/p>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>Transform the categorical data into numerical labels:<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\npythonCopy codeencoded_data = label_encoder.transform(categorical_data)\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">pythonCopy code<code>encoded_data = label_encoder.transform(categorical_data)\n<\/code><\/pre>\n\n\n\n<p>The <code>transform<\/code> method takes the original categorical data and returns an array with the corresponding numerical labels.<\/p>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li>If needed, you can also reverse the encoding to obtain the original categorical values using the <code>inverse_transform<\/code> method:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">pythonCopy code<code>original_data = label_encoder.inverse_transform(encoded_data)\n<\/code><\/pre>\n\n\n\n<p>Label encoding can also be applied to multiple columns or features simultaneously. You can repeat steps 3-5 for each categorical column you want to encode.<\/p>\n\n\n\n<p>It is important to note that label encoding introduces an arbitrary order to the categorical values, which may lead to incorrect assumptions by the model. To avoid this issue, you can consider using one-hot encoding or other methods such as ordinal encoding, which provide more appropriate representations for categorical data.<\/p>\n\n\n\n<p>Label encoding is a simple and effective way to convert categorical variables into numerical form. By using the LabelEncoder class from scikit-learn, you can easily encode your categorical data and prepare it for further analysis or input into machine learning algorithms.<\/p>\n\n\n\n<p>Now, let us first briefly understand what data types are and its scale. It is important to know this for us to proceed with categorical variable encoding. Data can be classified into three types, namely, <strong>structured data, semi-structured, <\/strong>and<strong> unstructured data<\/strong>.&nbsp;<\/p>\n\n\n\n<p>Structured data denotes that the data represented is in matrix form with rows and columns. The data can be stored in <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/sql-for-data-science\" target=\"_blank\" rel=\"noreferrer noopener\">database SQL in a table<\/a>, CSV with delimiter separated, or excel with rows and columns.<\/p>\n\n\n\n<p>The data which is not in matrix form can be classified into semi-Structured data (data in XML, JSON format) or unstructured data (emails, images, log data, videos, and textual data).<\/p>\n\n\n\n<p>Let us say, for given data science or machine learning business problem if we are dealing with only structured data and the data collected is a combination of both Categorical variables and Continuous variables, most of the machine learning algorithms will not understand, or not be able to deal with categorical variables. Meaning, that machine learning algorithms will perform better in terms of accuracy and other performance metrics when the <strong>data is represented as a number<\/strong> instead of categorical to a model for training and testing.&nbsp;<\/p>\n\n\n\n<p>Deep learning techniques such as the Artificial Neural network expect data to be numerical. Thus, categorical data must be encoded to numbers before we can use it to fit and evaluate a model.<\/p>\n\n\n\n<p>Few ML algorithms such as Tree-based (<a aria-label=\"Decision Tree (opens in a new tab)\" href=\"https:\/\/www.mygreatlearning.com\/blog\/decision-tree-algorithm\/\" target=\"_blank\" rel=\"noreferrer noopener\">Decision Tree<\/a>, Random Forest ) do a better job in handling categorical variables. The best practice in any data science project is to transform categorical data into a numeric value.&nbsp;<\/p>\n\n\n\n<p>Now, our objective is clear. Before building any statistical models, <a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-machine-learning\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"machine learning (opens in a new tab)\">machine learning<\/a>, or deep learning models, we need to transform or encode categorical data to numeric values. Before we get there, we will understand different types of categorical data as below.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Explore Data Science Program<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/professional-education-gl.mit.edu\/mit-online-data-science-program\" class=\"courses-cta-title-link\">MIT Professional Education's Data Science Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Gain the expertise top companies seek and open doors to Data Science jobs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Duration: 12 weeks<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>Ratings: 3<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/professional-education-gl.mit.edu\/mit-online-data-science-program\" class=\"courses-cta-button\">\n                Discover the Program\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"nominal-scale\"><strong>Nominal Scale<\/strong><\/h2>\n\n\n\n<p>The nominal scale refers to variables that are just named and are used for labeling variables. Note that all of A nominal scale refers to variables that are names. They are used for labeling variables. Note that all of these scales do not overlap with each other, and none of them has any numerical significance.&nbsp;<\/p>\n\n\n\n<p>Below are the examples that are shown for nominal scale data. Once the data is collected, we should usually assign a numerical code to represent a nominal variable.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-35.png\"><img decoding=\"async\" width=\"670\" height=\"340\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-35.png\" alt=\"\" class=\"wp-image-18981\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-35.png 670w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-35-300x152.png 300w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/figure>\n\n\n\n<p>For example, we can assign a numerical code 1 to represent Bangalore, 2 for Delhi, 3 for Mumbai, and 4 for Chennai for a categorical variable- in which place do you live. Important to note that the numerical value assigned does not have any mathematical value attached to them. Meaning, that basic mathematical operations such as addition, subtraction, multiplication, or division are pointless. Bangalore + Delhi or Mumbai\/Chennai does not make any sense.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ordinal-scale\"><strong>Ordinal Scale<\/strong><\/h2>\n\n\n\n<p>An Ordinal scale is a variable in which the value of the data is captured from an ordered set. For example, customer feedback survey data uses a Likert scale that is finite, as shown below.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-36.png\"><img decoding=\"async\" width=\"554\" height=\"274\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-36.png\" alt=\"\" class=\"wp-image-18982\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-36.png 554w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-36-300x148.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-36-324x160.png 324w\" sizes=\"(max-width: 554px) 100vw, 554px\" \/><\/figure>\n\n\n\n<p>In this case, let\u2019s say the feedback data is collected using a five-point Likert scale. The numerical code 1, is assigned to Poor, 2 for Fair, 3 for Good, 4 for Very Good, and 5 for Excellent. We can observe that 5 is better than 4, and 5 is much better than 3. But if you look at excellent minus good, it is meaningless.&nbsp;<\/p>\n\n\n\n<p>We very well know that most machine learning algorithms work exclusively with numeric data. That is why we need to encode categorical features into a representation compatible with the models. Hence, we will cover some popular encoding approaches:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Label encoding<\/li>\n\n\n\n<li>One-hot encoding<\/li>\n\n\n\n<li>Ordinal Encoding<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"label-encoding\"><strong>Label Encoding<\/strong><\/h2>\n\n\n\n<p>In label encoding in Python, we replace the categorical value with a numeric value between <strong>0 and the number of classes minus 1. <\/strong>If the categorical variable value contains 5 distinct classes, we use (0, 1, 2, 3, and 4).<\/p>\n\n\n\n<p>To understand label encoding with an example, let us take COVID-19 cases in India across states. If we observe the below data frame, the State column contains a categorical value that is not very machine-friendly and the rest of the columns contain a numerical value. Let us perform Label encoding for State Column.<\/p>\n\n\n\n<p>From the below image, after label encoding, the numeric value is assigned to each of the categorical values. You might be wondering why the numbering is not in sequence (Top-Down), and the answer is that the numbering is assigned in alphabetical order. Delhi is assigned 0 followed by Gujarat as 1 and so on.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-37.png\"><img decoding=\"async\" width=\"600\" height=\"230\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-37.png\" alt=\"\" class=\"wp-image-18983\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-37.png 600w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/image-37-300x115.png 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"label-encoding-using-python\"><strong>Label Encoding using Python<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Before we proceed with label encoding in <a aria-label=\"Python (opens in a new tab)\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python-tutorial-for-beginners-a-complete-guide\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a>, let us import important data science libraries such as pandas and NumPy.<\/li>\n\n\n\n<li>Then, with the help of panda, we will read the Covid19_India data file which is in CSV format and check if the data file is loaded properly. With the help of info(). We can notice that a state datatype is an object. Now we can proceed with LabelEncoding.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p><strong>Label Encoding can be performed in 2 ways namely:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>LabelEncoder class using scikit-learn library&nbsp;<\/li>\n\n\n\n<li>Category codes<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"approach-1-scikit-learn-library-approach\"><strong>Approach 1 - scikit-learn library approach<\/strong><\/h4>\n\n\n\n<p>As Label Encoding in Python is part of data preprocessing, hence we will take an help of <strong>preprocessing<\/strong> module from <strong>sklearn<\/strong> package and import <strong>LabelEncoder<\/strong> class as below:<\/p>\n\n\n\n<p>And then:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create an instance of <strong>LabelEncoder() <\/strong>and store it in<strong> labelencoder <\/strong>variable\/object<\/li>\n\n\n\n<li>Apply fit and transform which does the trick to assign numerical value to categorical value and the same is stored in new column called \u201cState_N\u201d<\/li>\n\n\n\n<li>Note that we have added a new column called \u201cState_N\u201d which contains numerical value associated to categorical value and still the column called State is present in the dataframe. This column needs to be removed before we feed the final preprocess data to machine learning model to learn<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"approach-2-category-codes\"><strong>Approach 2 \u2013 Category Codes<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>As you had already observed that \"State\" column datatype is an object type which is by default hence, need to convert \"State\" to a category type with the help of pandas<\/li>\n\n\n\n<li>We can access the codes of the categories by running covid19[\u201cState].cat.codes<\/li>\n<\/ol>\n\n\n\n<p>One potential issue with label encoding is that most of the time, there is no relationship of any kind between categories, while label encoding introduces a relationship.&nbsp;<\/p>\n\n\n\n<p>In the above six classes\u2019 example for \u201cState\u201d column, the relationship looks as follows: 0 &lt; 1 &lt; 2 &lt; 3 &lt; 4 &lt; 5. It means that numeric values can be misjudged by algorithms as having some sort of order in them. This does not make much sense if the categories are, for example, States.<\/p>\n\n\n\n<p>There is no such relation in the original data with the actual State names, but, by using numerical values as we did, a number-related connection between the encoded data might be made. To overcome this problem, we can use one-hot encoding as explained below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"one-hot-encoding\"><strong>One-Hot Encoding<\/strong><\/h2>\n\n\n\n<p>In this approach, for each category of a feature, we create a new column (sometimes called a dummy variable) with binary encoding (0 or 1) to denote whether a particular row belongs to this category.&nbsp;<\/p>\n\n\n\n<p>Let us consider the previous<strong> State<\/strong> column, and from the below image, we can notice that new columns are created starting from state name Maharashtra till Uttar Pradesh, and there are 6 new columns created. 1 is assigned to a particular row that belongs to this category, and 0 is assigned to the rest of the row that does not belong to this category.&nbsp;<\/p>\n\n\n\n<p>A potential drawback of this method is a significant increase in the dimensionality of the dataset (which is called a Curse of Dimensionality).<\/p>\n\n\n\n<p>Meaning, one-hot encoding is the fact that we are creating additional columns, one for each unique value in the set of the categorical attribute we'd like to encode. So, if we have a categorical attribute that contains, say, 1000 unique values, that one-hot encoding will generate 1,000 additional new attributes and this is not desirable.<\/p>\n\n\n\n<p>To keep it simple, one-hot encoding is quite a powerful tool, but it is only applicable for categorical data that have a low number of unique values.<\/p>\n\n\n\n<p>Creating dummy variables introduces a form of redundancy to the dataset. If a feature has three categories, we only need to have two dummy variables because, if an observation is neither of the two, it must be the third one. This is often referred to as the <strong>dummy-variable trap<\/strong>, and it is a best practice to always remove one dummy variable column (known as the reference) from such an encoding.<\/p>\n\n\n\n<p>Data should not get into dummy variable traps that will lead to a problem known as <strong>multicollinearity<\/strong>. Multicollinearity occurs where there is a relationship between the independent variables, and it is a major threat to multiple linear regression and logistic regression problems.<\/p>\n\n\n\n<p>To sum up, we should avoid label encoding in Python when it introduces false order to the data, which can, in turn, lead to incorrect conclusions. Tree-based methods (decision trees, Random Forest) can work with categorical data and label encoding. However, for algorithms such as linear regression, models calculating distance metrics between features (k-means clustering, k-Nearest Neighbors) or Artificial Neural Networks (ANN) are one-hot encoding.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"one-hot-encoding-using-python\"><strong>One-Hot Encoding using Python<\/strong><\/h2>\n\n\n\n<p>Now, let's see how to apply one-hot encoding in Python. Getting back to our example, in Python, this process can be implemented using 2 approaches as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>scikit-learn library&nbsp;<\/li>\n\n\n\n<li>Using Pandas<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"approach-1-scikit-learn-library-approach\"><strong>Approach 1 - scikit-learn library approach<\/strong><\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>As one-hot encoding is also part of data preprocessing, hence we will take an help of preprocessing module from sklearn package and them import OneHotEncoder class as below<\/li>\n\n\n\n<li>Instantiate&nbsp;the&nbsp;OneHotEncoder&nbsp;object, note that parameter <strong>drop = \u2018first\u2019 will handle dummy variable traps<\/strong><\/li>\n\n\n\n<li>Perform OneHotEncoding for categorical variable <\/li>\n<\/ol>\n\n\n\n<p>4. Merge One Hot Encoded Dummy Variables to Actual data frame but do not forget to remove the actual column called \u201cState\u201d<br>5. From the below output, we can observe, dummy variable trap has been taken care<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"approach-2-using-pandas-with-the-help-of-get_dummies-function\"><strong>Approach 2 \u2013 Using Pandas: with the help of get_dummies function<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>As we all know, one-hot encoding is such a common operation in analytics,&nbsp;that pandas provide a function to get the corresponding new features representing the categorical variable.<\/li>\n\n\n\n<li>We are considering the same dataframe called \u201ccovid19\u201d and imported pandas library which is sufficient to perform one hot encoding<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>As you notice below code, this generates a new DataFrame containing five indicator columns, because as explained earlier for modeling we don't need one indicator variable for each category; for a categorical feature with K categories, we need only K-1 indicator variables. In our example, \u201cState_Delhi\u201d was removed<\/li>\n\n\n\n<li>In the case of 6 categories, we need only five indicator variables to preserve the information <strong>(and avoid collinearity).<\/strong> That is why the <em>pd.get_dummies<\/em> function has another Boolean argument, drop_first=True, which drops the first category<\/li>\n\n\n\n<li>Since the&nbsp;<em>pd.get_dummies<\/em>&nbsp;function&nbsp;generates another DataFrame, we need to concatenate (or add) the&nbsp;columns to our original DataFrame and also don\u2019t forget to remove column called \u201cState\u201d<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Here, we use the&nbsp;<em>pd.concat<\/em>&nbsp;function, indicating with the&nbsp;axis=1&nbsp;argument&nbsp;that we want to concatenate the columns of the&nbsp;two&nbsp;DataFrames given in the list (which is the first argument of&nbsp;pd.concat). Don\u2019t forget to remove actual \u201cState\u201d column<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ordinal-encoding\"><strong>Ordinal Encoding<\/strong><\/h2>\n\n\n\n<p>An <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.preprocessing.OrdinalEncoder.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Ordinal Encoder<\/a> is used to encode categorical features into an ordinal numerical value (ordered set). This approach transforms categorical value into numerical value in ordered sets.<\/p>\n\n\n\n<p>This encoding technique appears almost similar to Label Encoding. But, label encoding would not consider whether a variable is ordinal or not, but in the case of ordinal encoding, it will assign a sequence of numerical values as per the order of data.<\/p>\n\n\n\n<p>Let\u2019s create a sample ordinal categorical data related to the customer feedback survey, and then we will apply the Ordinal Encoder technique. In this case, let\u2019s say the feedback data is collected using <strong>a Likert scale<\/strong> in which numerical code 1 is assigned to Poor, 2 for Good, 3 for Very Good, and 4 for Excellent. If you observe, we know that 5 is better than 4, 5 is much better than 3, but taking the difference between 5 and 2 is meaningless (Excellent minus Good is meaningless).  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ordinal-encoding-using-python\"><strong>Ordinal Encoding using Python<\/strong><\/h2>\n\n\n\n<p>With the help of Pandas, we will assign customer survey data to a variable called \u201cCustomer_Rating\u201d through a dictionary and then we can map each row for the variable as per the dictionary.<\/p>\n\n\n\n<p>That brings us to the end of the blog on Label Encoding in Python. We hope you enjoyed this blog. Also, check out this <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" target=\"_blank\" rel=\"noreferrer noopener\">Free Python for Beginners course<\/a> to learn the Fundamentals of Python. If you wish to explore more such courses and learn new concepts, join the <a aria-label=\"Great Learning Academy (opens in a new tab)\" href=\"https:\/\/www.mygreatlearning.com\/academy#our-courses\" target=\"_blank\" rel=\"noreferrer noopener\">Great Learning Academy<\/a> free course today.<\/p>\n\n\n\n<p>Embarking on a journey towards a career in data science opens up a world of limitless possibilities. Whether you\u2019re an aspiring data scientist or someone intrigued by the power of data, understanding the key factors that contribute to success in this field is crucial. The below path will guide you to become a proficient data scientist.<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter\"><table class=\"has-cyan-bluish-gray-background-color has-background\"><tbody><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/data-science\/courses\/certificates\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Course Certificates<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/data-science\/courses\/placements\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Course Placements<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/data-science\/courses\/syllabus\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Course Syllabus<\/a><\/td><\/tr><tr><td><a href=\"https:\/\/www.mygreatlearning.com\/data-science\/courses\/eligibility\" target=\"_blank\" rel=\"noreferrer noopener\">Data Science Course Eligibility<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Label encoding is a technique used in machine learning and data analysis to convert categorical variables into numerical format. It is particularly useful when working with algorithms that require numerical input, as most machine learning models can only operate on numerical data. In this explanation, we'll explore how label encoding works and how to [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":18992,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[36799,36796],"content_type":[],"class_list":["post-18980","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-artificial-intelligence","tag-machine-learning","tag-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>What is Label Encoding in Python | Great Learning<\/title>\n<meta name=\"description\" content=\"In label encoding in python, we replace the categorical value with a numeric value between 0 and the number of classes minus 1. Learn more!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Label Encoding in Python\" \/>\n<meta property=\"og:description\" content=\"In label encoding in python, we replace the categorical value with a numeric value between 0 and the number of classes minus 1. Learn more!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-08T04:47:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-12-18T15:01:11+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1253\" \/>\n\t<meta property=\"og:image:height\" content=\"836\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Label Encoding in Python\",\"datePublished\":\"2023-11-08T04:47:38+00:00\",\"dateModified\":\"2024-12-18T15:01:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/\"},\"wordCount\":2512,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/iStock-1154268654.jpg\",\"keywords\":[\"Machine Learning\",\"python\"],\"articleSection\":[\"AI and Machine Learning\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/\",\"name\":\"What is Label Encoding in Python | Great Learning\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/iStock-1154268654.jpg\",\"datePublished\":\"2023-11-08T04:47:38+00:00\",\"dateModified\":\"2024-12-18T15:01:11+00:00\",\"description\":\"In label encoding in python, we replace the categorical value with a numeric value between 0 and the number of classes minus 1. Learn more!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/iStock-1154268654.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/iStock-1154268654.jpg\",\"width\":1253,\"height\":836,\"caption\":\"label encoding in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/label-encoding-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AI and Machine Learning\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/artificial-intelligence\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Label Encoding in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"What is Label Encoding in Python | Great Learning","description":"In label encoding in python, we replace the categorical value with a numeric value between 0 and the number of classes minus 1. Learn more!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Label Encoding in Python","og_description":"In label encoding in python, we replace the categorical value with a numeric value between 0 and the number of classes minus 1. Learn more!","og_url":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2023-11-08T04:47:38+00:00","article_modified_time":"2024-12-18T15:01:11+00:00","og_image":[{"width":1253,"height":836,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Label Encoding in Python","datePublished":"2023-11-08T04:47:38+00:00","dateModified":"2024-12-18T15:01:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/"},"wordCount":2512,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg","keywords":["Machine Learning","python"],"articleSection":["AI and Machine Learning"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/","url":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/","name":"What is Label Encoding in Python | Great Learning","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg","datePublished":"2023-11-08T04:47:38+00:00","dateModified":"2024-12-18T15:01:11+00:00","description":"In label encoding in python, we replace the categorical value with a numeric value between 0 and the number of classes minus 1. Learn more!","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg","width":1253,"height":836,"caption":"label encoding in python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/label-encoding-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"AI and Machine Learning","item":"https:\/\/www.mygreatlearning.com\/blog\/artificial-intelligence\/"},{"@type":"ListItem","position":3,"name":"Label Encoding in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg",1253,836,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654-1024x683.jpg",1024,683,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg",1253,836,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg",1253,836,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg",640,427,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg",96,64,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/iStock-1154268654.jpg",150,100,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Introduction Label encoding is a technique used in machine learning and data analysis to convert categorical variables into numerical format. It is particularly useful when working with algorithms that require numerical input, as most machine learning models can only operate on numerical data. In this explanation, we'll explore how label encoding works and how to&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/18980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=18980"}],"version-history":[{"count":42,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/18980\/revisions"}],"predecessor-version":[{"id":111036,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/18980\/revisions\/111036"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/18992"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=18980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=18980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=18980"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=18980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}