title: Plot feature importance in RandomForestRegressor sklearn
body: <p>I Am new in Data Science. I am trying to find out the feature importance ranking for my dataset. I already applied Random forest and got the output.</p>
  
  <p>Here is my code:</p>
  
  <pre><code># importing libraries
  
  import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  %matplotlib inline
  
  # importing dataset
  
  dataset=pd.read_csv('Churn_Modelling.csv')
  X = dataset.iloc[:,3:12].values
  Y = dataset.iloc[:,13].values
  
  #encoding catagorical data
  
  from sklearn.preprocessing import LabelEncoder, OneHotEncoder
  
  #country
  labelencoder_X_1= LabelEncoder()
  X[:,1]=labelencoder_X_1.fit_transform(X[:,1])
  
  #gender
  labelencoder_X_2= LabelEncoder()
  X[:,2]=labelencoder_X_2.fit_transform(X[:,2])
  
  onehotencoder = OneHotEncoder(categorical_features=[0])
  X = onehotencoder.fit_transform(X).toarray()
  
  
  #spliting dataset into test set and train set
  
  from sklearn.model_selection import train_test_split
  X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = 0.20)
  
  from sklearn.ensemble import RandomForestRegressor
  
  regressor = RandomForestRegressor(n_estimators=20, random_state=0)  
  regressor.fit(X_train, y_train) 
  </code></pre>
  
  <p>In the importance part i almost copied the example shown in :
  <a href="https://scikit-learn.org/stable/auto_examples/ensemble/plot_forest_importances.html" rel="nofollow noreferrer">https://scikit-learn.org/stable/auto_examples/ensemble/plot_forest_importances.html</a></p>
  
  <p>Here is the code:</p>
  
  <pre><code>#feature importance
  from sklearn.ensemble import ExtraTreesClassifier
  
  importances = regressor.feature_importances_
  std = np.std([tree.feature_importances_ for tree in regressor.estimators_],
               axis=0)
  indices = np.argsort(importances)[::-1]
  print("Feature ranking:")
  
  for f in range(X.shape[1]):
      print("%d. feature %d (%f)" % (f + 1, indices[f], importances[indices[f]]))
  
  # Plot the feature importances of the forest
  plt.figure()
  plt.title("Feature importances")
  plt.bar(range(X.shape[1]), importances[indices],
         color="r", yerr=std[indices], align="center")
  plt.xticks(range(X.shape[1]), indices)
  plt.xlim([-1, X.shape[1]])
  plt.show()
  
  </code></pre>
  
  <p>I am expecting the output shown in the documentation. Can Anyone Help me please ? Thanks in Advance.</p>
  
  <p>My dataset is here:
  <a href="https://i.stack.imgur.com/M4iKh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M4iKh.png" alt="enter image description here"></a></p>