'Scikit Learn: Logistic Regression model coefficients: Clarification

I need to know how to return the logistic regression coefficients in such a manner that I can generate the predicted probabilities myself.

My code looks like this:

lr = LogisticRegression()
lr.fit(training_data, binary_labels)

# Generate probabities automatically
predicted_probs = lr.predict_proba(binary_labels)

I had assumed the lr.coeff_ values would follow typical logistic regression, so that I could return the predicted probabilities like this:

sigmoid( dot([val1, val2, offset], lr.coef_.T) )

But this is not the appropriate formulation. Does anyone have the proper format for generating predicted probabilities from Scikit Learn LogisticRegression? Thanks!



Solution 1:[1]

The easiest way is by calling coef_ attribute of LR classifier:

Definition of coef_ please check Scikit-Learn document:

See example:

from sklearn.linear_model import LogisticRegression

clf = LogisticRegression()  
clf.fit(x_train,y_train)  

weight = classifier.coef_  

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yinhao