逻辑回归python录取几率_Python SKLearn:逻辑回归概率

I am using the Python SKLearn module to perform logistic regression. I have a dependent variable vector Y (taking values from 1 of M classes) and independent variable matrix X (with N features). My code is

LR = LogisticRegression()

LR.fit(X,np.resize(Y,(len(Y))))

My question is, what does LR.coef_ and LR.intercept_ represent. I initially thought they held the values 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) is the probability that observation with features [X1, ... ,XN] is in class i. However when I try to convert

V = X*LR.coef_.transpose()

U = V + LR.intercept_

A = np.exp(U)

A/(1+A)

so that A is the matrix of p(1) ... p(M) for the observations in X. This should be the same value as

LR.predict_proba(X)

however they are close, but different. Why is this?

解决方案

The coef_ and intercept_ attributes represent what you think, your probability calculations are off because you forgot to normalize: after

P = A / (1 + A)

you should do

P /= P.sum(axis=1).reshape((-1, 1))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值