0
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Romain Reboulleau Dec 16 '19 at 5:24
  • $\begingroup$ Thanks for your response. I have set the threshold to a very small positive value (0.000001) to get this done. $\endgroup$ – Soham Dhole Dec 17 '19 at 9:43
1
$\begingroup$

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

You can specify the threshold that you want when you want to select features. You can add this transformer in a scikit-learn pipeline as well.

| improve this answer | |
$\endgroup$

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.