I have produced a list based on feature importance using the code below. How do I select the features indexes whose scores are greater than 0.00100? The code I used is below:
importance = rf.feature_importances_
# summarise feature importance
for i,v in enumerate(importance):
print('Feature: %0d, Score: %.5f' % (i,v))
# plot feature importance
pyplot.bar([x for x in range(len(importance))], importance)
pyplot.show()
Feature: 0, Score: 0.00020
Feature: 1, Score: 0.00097
Feature: 2, Score: 0.00122
Feature: 3, Score: 0.00115
Feature: 4, Score: 0.00012
I have tried
X = importance.loc[:, importance.loc['importance'] <= 0.001]
and
X = importance[importance['Score'] > 0.00100]
but it obviously returns an error:
AttributeError: 'numpy.ndarray' object has no attribute 'loc'
and
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
respectively.
I believe I can call original columns later once I know the features indexes using:
X = X.iloc[:,[0, 3, 18, 27, 31, 32, 39, 67, 90, 114]]
Except there is a better way to call them straight away into rather than doing a copy and paste into the iloc.