0
$\begingroup$

I've this code to print the importance of each variable on my model:

importances = trained_model.feature_importances_
std = np.std([trained_model.feature_importances_ for trained_model in trained_model.estimators_], axis=0)
indices = np.argsort(importances)[::-1]

# Print the feature ranking
print("Feature ranking:")

for f in range(training_features.shape[1]):
    print("%d. feature %d (%f)" % (f + 1, indices[f], importances[indices[f]]))

I print a lot of variables with feature ranking as 0.0. Should I remove that variables? I can I do it using Python?

Like this:

df = df.drop('Col_A', 1) WHERE importances[indices[f]] = 0

Thanks!

$\endgroup$
  • $\begingroup$ Yes they can be removed if it's 0 like thresholding and then again we can retrain our .ideal to see the difference? $\endgroup$ – Aditya Mar 1 '18 at 17:23
0
$\begingroup$

Assuming your features are df[X] and your target is df[y], I would just do the following:

keepfeatures = X[trained_model.feature_importances_ > 0]
keepfeatures.append(y)

df = df[keepfeatures]
$\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.