Basics: What is the correct sequence for preparing simple data for ML? I'm just getting started with ML and am busy with my first Kaggle competition (the titanic one).

I was just wondering what would be the best way to organise the data to avoid redundancy with the following steps:


Feature Selection
Account for gaps in data(Imputing)
One hot encoding to allow non numerical features
Split data into training and validation sets
Then proceed to fit and predict with the model.


My main query is whether it is better to split the data before encoding it, or to only do the split after completing the encoding?
The same encoding needs to happen on both the train and the test set. So, encode before splitting.