Imbalanced Data how to use random forest to select important variables? I am trying to use random forest to select important variables out of 15K features and fit them into logistic regression. My evaluation is based on F1 score. Dataset 2 classes ratio are around: 99.5:0.5. 

Here is where 15K features come from: 
Initally I have 2000 features, after dumminize them (only taking top 100 categories from categoritical variable) it became 16K. After removing zero variance it became 15K. I didn't want to remove near zero variance because of my class imbalance ratio is also very small. I tried removing near zero variance features before and it significantly reduces the number of features, however the logistic regression result was also not good.

However, after using grid search, random forest still has very low f1 score for cross validation. (less than 0.01)

Also I tried undersampling for the training data to make it 1:1, random forest still has bad F1 score for cross validation. :(

So I was thinking about not selecting the important variables and just fit all features to logistic regression.

Due to memory issue, I am not able to fit all 15K features into logistic regression directly but if I select important variables from random forest, they do not generalize for unseen test data. 

Any ideas on how to solve the problem?
I know one alternative could be using hashing so I could fit all 15K features.
15K features is a lot of features. I'd bet your 0.01 F1 score is a direct result of having so many features. Without knowing more details about your data it is hard to suggest a more sensible alternative. I'd want it to be closer to 100 features rather than 15,000 though. Are these features extracted from text? N-grams?
Regarding your feature selection problem, the first step is to eliminate any features with no variance (all samples the same), then one can utilis various statistical methods for selecting features to retain those with high variance (sklearn has great libraries for this: Feature selection).
One could also utilize Ranked Guide Iterative Feature Elimination (RGIFE) for this purpose, which uses random forests: RGIFE - Ranked Guided Iterative Feature Elimination
P.S. Your class ratio is very skewed as well. Once you're all settled with a more reasonable dataset in feature space I'd consider either undersampling the larger class, oversampling the smaller class or a combination of both, and keep an eye on the resulting confusion matrices when performing your evaluation.