Created
August 6, 2020 02:13
-
-
Save matrix303/0058f3287ff7cab1a91e8d4ae9f4a4cd to your computer and use it in GitHub Desktop.
Feature Ranking #python #DataScience
This file contains hidden or 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
| 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