We are applying feature selection for train data. Assume that we are having 1000 selected features. The testing data contains more than 1000 features. It results in prediction error "The number of features at training time in scikit learn". How can we reduce the number of features in testing data? Should we apply feature selection for testing data also?


You should have the same features as the training time at the testing time. Normally, you do some feature selection or feature extraction at the training time and do the same process in the test time. For example, if by feature selection you find out that it is enough to have a subset of features, you should use the same subset of features at the test time. Or if by feature extraction you define a new feature by combining the existing features, you should use the same function for obtaining the new feature at the test time.

I emphasize that you should NOT use a new feature selection/extraction at the test time. You should use the same features that are selected (or extracted) at the training time.

  • $\begingroup$ The same feature selection can be applied. I agree with that. But it will not result in same features that are in training data. How to accomplish this task? $\endgroup$ – banu Mar 30 '17 at 5:30
  • $\begingroup$ As mentioned, you should not use the same feature selection process. You should use the same features that are selected during training time. For example, say during the training you find out that the most relevant features are $f_2, f_3, f_4$. During the test time, you should use the same features $f_2, f_3, f_4$. $\endgroup$ – Hossein Mar 30 '17 at 5:37
  • $\begingroup$ Please refer this link and say. How can i accomplish it? stats.stackexchange.com/questions/270472/… $\endgroup$ – banu Mar 30 '17 at 5:38
  • $\begingroup$ How can i extract the same features in the test set also? Which method can i follow? $\endgroup$ – banu Mar 30 '17 at 5:40
  • $\begingroup$ During training you determine which features to keep and during testing you just keep those features and remove other features. $\endgroup$ – Hossein Mar 30 '17 at 5:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.