So , thing is I was working on titanic dataset . During data preprocessing when i tried to use LabelEncoder I got the following error. Here X contains the train set while X1 contains the test set. As clear both train and test set are same . but code only works fine on test set while not train set. Anyone who can show me my mistake.