Python Scikit Learn:逻辑回归模型系数:澄清
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18993867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Scikit Learn: Logistic Regression model coefficients: Clarification
提问by zbinsd
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:
我曾假设 lr.coeff_ 值将遵循典型的逻辑回归,以便我可以像这样返回预测概率:
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!
但这不是适当的表述。有没有人有从 Scikit Learn LogisticRegression 生成预测概率的正确格式?谢谢!
采纳答案by prgao
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_
看看文档(http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html),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.
coef_ array, shape = [n_classes-1, n_features] 决策函数中特征的系数。coef_ 是从 raw_coef_ 派生的只读属性,它遵循 liblinear 的内部存储器布局。截距数组,形状 = [n_classes-1] 截距(又名偏差)添加到决策函数中。仅当参数intercept 设置为True 时才可用。
try:
尝试:
sigmoid( dot([val1, val2], lr.coef_) + lr.intercept_ )