Scikit学习:Logistic回归模型系数:澄清度 [英] 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.
我的代码如下:
lr = LogisticRegression()
lr.fit(training_data, binary_labels)
# Generate probabities automatically
predicted_probs = lr.predict_proba(binary_labels)
我假设lr.coeff_值将遵循典型的逻辑回归,因此我可以返回如下所示的预测概率:
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) )
但这不是适当的表述.有没有人具有从Scikit Learn LogisticRegression生成预测概率的正确格式? 谢谢!
But this is not the appropriate formulation. Does anyone have the proper format for generating predicted probabilities from Scikit Learn LogisticRegression? Thanks!
推荐答案
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_数组,形状= [n_classes-1,n_features]的系数 决策功能中的功能. coef_是派生的只读属性 来自raw_coef_,遵循liblinear的内部内存布局. 截取数组,形状= [n_classes-1]已添加截距(也称为偏差) 决策功能.仅当参数 截距设置为True.
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.
尝试:
sigmoid( dot([val1, val2], lr.coef_) + lr.intercept_ )
这篇关于Scikit学习:Logistic回归模型系数:澄清度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!