lahaxs.blogg.se

Label encoding in python
Label encoding in python







label encoding in python label encoding in python

If you’re interested in checking out the documentation, you can find it here. After running this piece of code, if you check the value of x, you’ll see that the three countries in the first column have been replaced by the numbers 0, 1, and 2. We’ve assumed that the data is in a variable called ‘x’. from sklearn.preprocessing import LabelEncoder labelencoder = LabelEncoder() x = labelencoder.fit_transform(x) So all we have to do, to label encode the first column, is import the LabelEncoder class from the sklearn library, fit and transform the first column of the data, and then replace the existing text data with the new encoded data. So before we can run a model, we need to make this data ready for the model.Īnd to convert this kind of categorical text data into model-understandable numerical data, we use the Label Encoder class. As you might know by now, we can’t have text in our data if we’re going to run any kind of model on it. In this example, the first column is the country column, which is all text.









Label encoding in python