title: How to get feature importance in Decision Tree?
body: <p>I have a dataset of reviews which has a class label of positive/negative. I am applying Decision Tree to that reviews dataset. Firstly, I am converting into a Bag of words. Here sorted_data['Text'] is reviews and final_counts is a sparse matrix.</p>
  
  <p>I am splitting the data into train and test dataset.</p>
  
  <pre><code>X_tr, X_test, y_tr, y_test = cross_validation.train_test_split(sorted_data['Text'], labels, test_size=0.3, random_state=0)
  
  # BOW
  count_vect = CountVectorizer() 
  count_vect.fit(X_tr.values)
  final_counts = count_vect.transfrom(X_tr.values)
  </code></pre>
  
  <p>applying the Decision Tree algorithm as follows</p>
  
  <pre><code># instantiate learning model k = optimal_k
  # Applying the vectors of train data on the test data
  optimal_lambda = 15
  final_counts_x_test = count_vect.transform(X_test.values)
  bow_reg_optimal = DecisionTreeClassifier(max_depth=optimal_lambda,random_state=0)
  
  # fitting the model
  bow_reg_optimal.fit(final_counts, y_tr)
  
  # predict the response
  pred = bow_reg_optimal.predict(final_counts_x_test)
  
  # evaluate accuracy
  acc = accuracy_score(y_test, pred) * 100
  print('\nThe accuracy of the Decision Tree for depth = %f is %f%%' % (optimal_lambda, acc))
  </code></pre>
  
  <p><strong>bow_reg_optimal</strong> is a decision tree classifier. Could anyone tell how to get the <strong>feature importance</strong> using the decision tree classifier?</p>