Scikit Learn: Logistic Regression model coefficients: Clarification

一曲冷凌霜 提交于 2019-12-29 11:35:10

问题


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!


回答1:


take a look at the documentations (http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html), offset coefficient isn't stored by lr.coef_

coef_ array, shape = [n_classes-1, n_features] Coefficient of the features in the decision function. coef_ is readonly property derived from raw_coef_ that follows the internal memory layout of liblinear. intercept_ array, shape = [n_classes-1] Intercept (a.k.a. bias) added to the decision function. It is available only when parameter intercept is set to True.

try:

sigmoid( dot([val1, val2], lr.coef_) + lr.intercept_ ) 


来源:https://stackoverflow.com/questions/18993867/scikit-learn-logistic-regression-model-coefficients-clarification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!