# Features selection/combination for random forest

I am working on using random forest to predict 1 or 0. I have about 20 variables available for modeling. I realized that if I put different variables will have different accuracy/sensitivity/specificity. I am wondering if there is a test or method can tell me which variables combination has the highest accuracy? Or which variable combination has the highest sensitivity and specificity respectively?

• Just use the feature_importance attribute of your random forest model in scikit-learn. It will the order the features in terms of importance for the model – enterML Dec 21 '17 at 17:19
The Random Forest model in sklearn has a feature_importances_ attribute to tell you which features are most important. Here is a helpful example.
There are a few other algorithms for selecting the best features that generalize to other models such as sequential backward selection and sequential forward selection. In the case of sequential forward selection, you begin by finding the single feature that provides you with the best accuracy. Then, you find the next feature in combination with the first that gives you the best accuracy. This pattern continues until you find $k$ features, where $k$ is the number of features you want to use. Sequential backward selection is just the opposite, where you start with all of the features and remove those which inhibit your accuracy the most. You can find more information on these algorithms here.