Skip to content

Instantly share code, notes, and snippets.

@matrix303
Created August 6, 2020 02:13
Show Gist options
  • Select an option

  • Save matrix303/0058f3287ff7cab1a91e8d4ae9f4a4cd to your computer and use it in GitHub Desktop.

Select an option

Save matrix303/0058f3287ff7cab1a91e8d4ae9f4a4cd to your computer and use it in GitHub Desktop.
Feature Ranking #python #DataScience
TOP_FEATURES = len(feature_list)
forest = RandomForestClassifier(n_estimators=10,max_depth=6)#, random_state=3)
forest.fit(l_mat[1],l_label[1])
importances = forest.feature_importances_
std = np.std(
[tree.feature_importances_ for tree in forest.estimators_],
axis=0
)
indices = np.argsort(importances)[::-1]
indices = indices[:TOP_FEATURES]
print('Top features:')
print('Num\t\tFeature\t\tImportance')
counter = 0
for f in range(TOP_FEATURES):
print('%d.\t\t%s\t\t(%f)' % (f + 1,DILC_features[indices[f]],importances[indices[f]]))
counter += importances[indices[f]]
print (counter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment