我正在使用 Python SKLearn 模块来执行逻辑回归。我有一个因变量向量Y
(从 M 类中的 1 个中获取值)和自变量矩阵X
(有 N 个特征)。我的代码是
LR = LogisticRegression()
LR.fit(X,np.resize(Y,(len(Y))))
我的问题是,什么是LR.coef_
and LR.intercept_
代表。我最初以为他们持有价值观intercept(i)
and coef(i,j)
s.t.
log(p(1)/(1-p(1))) = intercept(1) + coef(1,1)*X1 + ... coef(1,N)*XN
.
.
.
log(p(M)/(1-p(M))) = intercept(M) + coef(M,1)*X1 + ... coef(M,N)*XN
where p(i)
是具有特征的观察的概率[X1, ... ,XN]
正在上课i
。但是当我尝试转换时
V = X*LR.coef_.transpose()
U = V + LR.intercept_
A = np.exp(U)
A/(1+A)
so that A
是矩阵p(1) ... p(M)
对于观察结果X
。这应该与以下值相同
LR.predict_proba(X)
然而它们很接近,但又不同。为什么是这样?