I want to know feature names that a LogisticRegression() Model has used along with their corresponding weights in scikit-learn. I can access to weights using coef_, but i did not know how can pair them with their corresponding weights.

  • 3
    $\begingroup$ I think the model just returns the coef_ in the same order as your input features, so just print them out one by one $\endgroup$
    – Yang Song
    Mar 15, 2018 at 21:16
  • $\begingroup$ It's in the order of the columns by default... Also to get feature Importance from LR, take the absolute value of coefficients and apply a softmax on the same(be careful, some silver already do so in-built) $\endgroup$
    – Aditya
    Mar 16, 2018 at 0:18

2 Answers 2


We if you're using sklearn's LogisticRegression, then it's the same order as the column names appear in the training data. see below code.

#Train with Logistic regression
from sklearn.linear_model import LogisticRegression
from sklearn import metrics

model = LogisticRegression()
#Print model parameters - the names and coefficients are in same order

You may also verify using another library as below

import statsmodels.api as sm

I made a scenario:

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model.logistic import LogisticRegression
from sklearn.metrics import accuracy_score

max_features = 100
tfidf = TfidfVectorizer(max_features=max_features)#stop_words='english',)# norm = None)#)

texts_train = ['positive sample', 'again positive', 'negative sample', 'again negative']
target_train = [1,1,0,0]
texts_test = ['negative', 'positive']
target_test = [0,1]
texts_train1 = tfidf.fit_transform(texts_train)
texts_test1 = tfidf.transform(texts_test)
classifier = LogisticRegression()
classifier.fit(texts_train1, target_train)
predictions = classifier.predict(texts_test1)

print('accuracy (simple):', accuracy_score(target_test, predictions))

['again', 'negative', 'positive', 'sample']


array([[ 0. , -0.56718183, 0.56718183, 0. ]]) that makes sense!

  • $\begingroup$ @ keramat - does this means coefficients corresponds to the features in alphabetically sorted in ascending order? $\endgroup$
    – KGhatak
    Dec 8, 2019 at 12:46
  • $\begingroup$ Never mind, found the answer (same as the comments to the original post) $\endgroup$
    – KGhatak
    Dec 8, 2019 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.