- split the data into train and test
- fit your imputer based on the train data set (use just fit)
- use the fitted imputer and fill missing value in the training dataset (use transform)
- Train you decision tree based on the training dataset
Now you are done with the training step. start testing a follows
- Use imputer trained in step 2 and transform function to replace missing values in the test dataset
- Use the trained decision tree for test prediction and evaluating the performance of your model on the unseen test dataset
The data should be split at the beginning. As the name of "unseen" shows, we should not use any information from the test dataset when we are training the model; otherwise, it is data leakage.