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?
-
$\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 ReboulleauDec 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$– soham_dholeDec 17, 2019 at 9:43
1 Answer
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.