scikit-learn - LogisticRegression类的coef_属性解读

标签 scikit-learn logistic-regression

我有一个关于 coef_ 的问题(可能很愚蠢) sklearn.linear_model.LogisticRegression 的属性。

我适合LogisticRegression型号为Iris dataset仅使用两个特征(花瓣宽度和长度)。为了获得每个特征的权重,我使用 coef_属性并返回 3x2 数组。我知道我得到 3 行的原因是因为 3 类和一对一规则。

但是,我不明白为什么它只包含 w_1 和 w_2(或 theta_1 和 theta_2,具体取决于您使用的表示法)、特征 1 和 2 的系数,但缺少 w_0 (或 theta_0),即截距。

代码:

from sklearn import datasets
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression

iris = datasets.load_iris()

X = iris.data[:, [2,3]]
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0)

sc = StandardScaler()
sc.fit(X_train)
X_train_std = sc.transform(X_train)

lr = LogisticRegression(C = 1000, random_state=0)
lr.fit(X_train_std, y_train)
lr.coef_

最佳答案

属性“coef_”仅给出决策函数中特征的系数。

您可以使用以下方式获取拦截:

lr.intercept_

关于scikit-learn - LogisticRegression类的coef_属性解读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45536071/

相关文章:

python - 如何设置 curve_fit 的初始值以找到最佳优化,而不仅仅是局部优化?

python - 有没有什么方法可以可视化具有从一个热编码特征整合的分类特征的决策树(sklearn)?

python - 使用 SVD 进行降维,指定要保持的能量

python - 值错误 : multiclass-multioutput format is not supported using sklearn roc_auc_score function

python - tensorflow 逻辑回归

python - 对这些数据进行聚类的最佳算法是什么

python - 安娜 : keras/sklearn doesn't scale well

tensorflow - Softmax逻辑回归: Different performance by scikit-learn and TensorFlow

python - 将一列中的数组值转换为原始 DataFrame 的列的最佳方法是什么?

python - Coursera ML - 在 python 中实现正则化逻辑回归成本函数