Label Encoding in R

Hello,

I have performed label encoding using superml library in R

   library(superml)
   lbl <- LabelEncoder$new()
   train$Country <- lbl$fit_transform(train$Country)

when I applied the same encoder(lbl) to my test data set, it’s not giving the same rank to the country, which has been given to the country in train dataset. Instead its just assigning numbers in an order irrespective of anything

please help me out to fix this.

it would be great be you can share the relevant R code too.

Thanks in Advance

The CatEncoders option seems better.

© Copyright 2013-2019 Analytics Vidhya