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$
2
  • $\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$ Dec 16, 2019 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$ Dec 17, 2019 at 9:43

1 Answer 1

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.