1

Right now I have this, listing feature importances as numbers, how can i put the column names in the x axis?

from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from matplotlib import pyplot
X, y = make_classification(n_samples=2700, n_features=60, 
n_informative=5, n_redundant=5, random_state=1)

model = LogisticRegression()
model.fit(X, y)
importance = model.coef_[0]
for i,v in enumerate(importance):
    print('Feature: %0d, Score: %.5f' % (i,v))
pyplot.bar([x for x in range(len(importance))], importance)
pyplot.show()

The Output:

Feature: 0, Score: -0.11124
Feature: 1, Score: -0.04292
Feature: 2, Score: 0.00561

enter image description here

prof31
  • 75
  • 1
  • 7
  • using sklearn? Information is missing from the question. Feature names not evident from the question, so where do you find them? – creanion Aug 16 '22 at 15:41
  • Yes using sklearn logreg model. I'll update the post and include the code. – prof31 Aug 16 '22 at 15:46
  • Please fix the indentation in your example code. – wwii Aug 16 '22 at 16:00
  • `plot feature importance` looks like it should throw an Exception - if it does please fix. Please read and provide a [mre]. – wwii Aug 16 '22 at 16:02
  • Does this answer your question? [Matplotlib Xticks Values in Bar Chart](https://stackoverflow.com/questions/47838680/matplotlib-xticks-values-in-bar-chart) – Jody Klymak Aug 17 '22 at 15:59

0 Answers0