Skip to content

Instantly share code, notes, and snippets.

@dan0nchik
Created December 12, 2020 11:41
Show Gist options
  • Save dan0nchik/6b8294946efba91632fb04ec0fdab0b7 to your computer and use it in GitHub Desktop.
Save dan0nchik/6b8294946efba91632fb04ec0fdab0b7 to your computer and use it in GitHub Desktop.
Script for showing optimal features for classifying
from sklearn.ensemble import ExtraTreesClassifier
import matplotlib.pyplot as plt
model = ExtraTreesClassifier()
model.fit(X,y)
f = plt.figure(figsize=(10, 10))
print(model.feature_importances_) #use inbuilt class feature_importances of tree based classifiers
#plot graph of feature importances for better visualization
feat_importances = pd.Series(model.feature_importances_, index=X.columns)
feat_importances.nlargest(30).plot(kind='barh')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment