2
$\begingroup$

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?

Thanks in advance!

$\endgroup$
  • 2
    $\begingroup$ 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 $\endgroup$ – Nain Dec 21 '17 at 17:19
2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Thanks, @gingermander. It is very helpful information. I will use feature importances for the random forest and use the sequential backward/forward selection for the logistic regression model. $\endgroup$ – Joanna Dec 21 '17 at 20:06
  • $\begingroup$ Of course! Hope your project goes well. $\endgroup$ – gingermander Dec 21 '17 at 20:15

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.