How to select features which have non zero importance using SKLearn's Decision Trees Classifier?

I need to discard all the features which have zero importance and keep only those features which have non zero importance while implementing DecisionTreesClassifier. The feature importance here is determined using clf.feature_importance_ parameter of DecisionTreesClassifier. How can this be done?

• Hi, welcome to Data Science SE! What exactly is your question? Do you need the code instructions to perform the operation? If so, consider looking for the answer on Stack Overflow. It is likely that most features (all?) will have non-zero importance, are you looking for a way to define the threshold? In any case, please consider editing your question with more details about your problem and what you have tried to solve it up to now. – Romain Reboulleau Dec 16 '19 at 5:24
• Thanks for your response. I have set the threshold to a very small positive value (0.000001) to get this done. – Soham Dhole Dec 17 '19 at 9:43

You should use a sklearn.feature_selection.SelectFromModel instance: https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectFromModel.html