The following code works using a random forest model to give me a chart showing feature importance:
from sklearn.feature_selection import SelectFromModel
import matplotlib
clf = RandomForestClassifier()
clf = clf.fit(X_train,y_train)
clf.feature_importances_
model = SelectFromModel(clf, prefit=True)
test_X_new = model.transform(X_test)
matplotlib.rc('figure', figsize=[5,5])
plt.style.use('ggplot')
feat_importances = pd.Series(clf.feature_importances_, index=X_test.columns)
feat_importances.nlargest(20).plot(kind='barh',title = 'Feature Importance')
However I need to do the same for a logistic regression model. The following code produces an error:
from sklearn.feature_selection import SelectFromModel
import matplotlib
clf = LogisticRegression()
clf = clf.fit(X_train,y_train)
clf.feature_importances_
model = SelectFromModel(clf, prefit=True)
test_X_new = model.transform(X_test)
matplotlib.rc('figure', figsize=[5,5])
plt.style.use('ggplot')
feat_importances = pd.Series(clf.feature_importances_, index=X_test.columns)
feat_importances.nlargest(20).plot(kind='barh',title = 'Feature Importance')
I get
AttributeError: 'LogisticRegression' object has no attribute 'feature_importances_'
Can someone help where I am going wrong?

