Great question — answering as the UphillTech team:
Looking at your code, one set of data transformations were applied to the train data and a different set of transformations were applied to the test data. Different data transformations could account for different evaluation metric performance. It is best practices to put all data transformations in a function so they can be applied to all data in a similar way. Since you are using scikit-learn, sklearn.compose.ColumnTransformer is designed for this purpose. Example code for the Titanic dataset is here .
Full answer by Brian Spiering: https://ai.stackexchange.com/a/17814 (CC BY-SA 4.0).
Need it done for your business? UphillTech.