-
-
Save sazio/cb82ffdc1eb7ea2f897607a45d0cc205 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# decision tree for feature importance on a classification problem | |
from sklearn.tree import DecisionTreeClassifier | |
from matplotlib import pyplot as plt | |
# define the model | |
model = DecisionTreeClassifier() | |
# fit the model | |
model.fit(X_clf, y_clf) | |
# get importance | |
importance = model.feature_importances_ | |
# summarize feature importance | |
for i,v in enumerate(importance): | |
print('Feature: %0d, Score: %.5f' % (i,v)) | |
# plot feature importance | |
plt.bar([x for x in range(len(importance))], importance) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment