I am working with RandomForestRegressor in python and I want to create a diagram that will illustrate the ranking of the importance of a function. This is the code I used:
from sklearn.ensemble import RandomForestRegressor MT= pd.read_csv("MT_reduced.csv") df = MT.reset_index(drop = False) columns2 = df.columns.tolist()
Function value
features=df.columns[[3,4,6,8,9,10]] importances = model.feature_importances_ indices = np.argsort(importances) plt.figure(1) plt.title('Feature Importances') plt.barh(range(len(indices)), importances[indices], color='b', align='center') plt.yticks(range(len(indices)), features[indices]) plt.xlabel('Relative Importance')
This importance severity code was modified from an example found at http://www.agcross.com/2015/02/random-forests-in-python-with-scikit-learn/
When I try to replicate the code, my data gets the following error:
IndexError: index 6 is out of bounds for axis 1 with size 6
In addition, only one function with 100% importance is displayed on my diagram, where there are no labels.
Any help in solving this problem, so I can create this diagram, would be greatly appreciated.
source share