I have the column in my data frame
city
London
Paris
New York
.
.
I am label encoding the column and it assigns the 0 to London , 1 to Paris and 2 to New York . But when I pass single value for predictions from model I gives city name New York and it assigns the 0 to it . How it shall remains same , I want that if New York values assigns 2 by label encoder in training phase, it should assign 2 again at the predictions .
Code
from sklearn.preprocessing import LabelEncoder
labelencoder=LabelEncoder()
df['city']=labelencoder.fit_transform(df['city'])
You need to use
fitorfit_transformto fit the encoder, thentransformon the data that you want to encode to get labels (if you dofit_transformon that data, it will re-fit the encoder, and if you only pass one value, it will be encoded as 0):