What to do when the test data set has many "features" that are generated by dummfying a categorical variable that are not present in the training set Say you have a variable (in this case industry) that you dummify (one hot encode) hence creating many new features in both the training and test sets for which you are getting ready to run a machine learning model. However, this dummy variable generates by several hundred more variables (features) in the test set then the training set. 
What should you do?
 A: What about just throwing out all the columns that aren't present in the training set? We have learned nothing about those industries, so I don't think they can teach you anything about your response variable.
There might be algorithm specific answers, but thinking about it as a linear model, if they had a 0 in every column that remains for industry, they would get the intercept effect for industry, while every industry that had data would be slightly different than the intercept.
A: (This specific question is kinda old now, but the issue is common, and our answers are an enduring resource. So please ignore the untimeliness of this reply.) 
It appears from the description and comments that you've created an arbitrary sample of 8,000 observations for the training set, and that's not serving you well.
Obvious things you could do to help with that would be:


*

*increase the size of the training set,
and/or 

*develop a    stratified sampling method to split your data into
training vs test,    which forces in those predictors (industry
flags) you believe ought    to be included.


The quote "this dummy variable generates by several hundred more variables (features) in the test set then the training set" also suggests that your training dataset could be relatively wide relative to its height. In other words, you may have insufficient EPV (events per variable) to have a stable & credible model. Another reason to increase the size of the training data.
Personally, I'm always going start with a training set that is As Big As Possible. I'll only cut it down IF the training process chugs along for an intolerable amount of time. If the initial training set had been half of the available data ... i.e., 200k records rather than 8k ... it's likely that no time would have been wasted trying to understand and solve the "some industries aren't represented in the training data" problem that was created by the choice to use a small sample. Computer time is usually much cheaper than people-time. (That said, I don't deal with Amazon/Google-sized datasets.) 
