I've been reading a bunch of posts that advise people to not include test data when preprocessing. So I've proceeded by first setting aside a test dataset to be used to assess how well my classifier at the final stage.
I have two sources of data: clinical data and gene expression data. Since the gene expression data has many, many dimensions, I wanted to use PCA to reduce the number of dimensions to about 15. Then I combined the PCs with the clinical predictors to obtain a "full" features dataset. Then, I trained a model using
train in the
caret package. However, I want to use that classifier to make predictions, but when I put my test dataset into the
predict function, I get an error because the principal components are not in the test dataset.
So my question is, do I run PCA on the test dataset as well? Or am I misunderstanding the whole concept of preprocessing? Thank you!