Binary Classification - One Hot Encoding preventing me using Test Set I have a preprocessing pipeline that includes replacing missing values and onehotencoding for the categorical variables. 

When I try to use my model on the test set, it explains that the number of columns it expects differs. This is due to one hot encoding

One option I considered was passing the full dataset into the pipeline and then seperating into test and split. However, this causes data leakage as the missing values it capturing values from the testset.

Please let me know how to prevent this. 

Thanks,
You can use handle_unknown parameter of sklearn while encoding training data.

sklearn.preprocessing.OneHotEncoder(handle_unknown='ignore')


When this parameter is set to ‘ignore’ and an unknown category is encountered during transform, the resulting one-hot encoded columns for this feature will be all zeros.

Note : I assumed you are using scikit-learn.

Source : sklearn.preprocessing