逻辑回归的矩阵符号


15

在线性回归(平方损失)中,使用矩阵,我们对目标有一个非常简洁的表示法

minimize  Axb2

其中A是数据矩阵,x是系数,b是响应。

Logistic回归目标是否有类似的矩阵符号?我见过的所有符号都不能消除所有数据点的总和(像dataLlogistic(y,βTx))。


编辑:感谢joceratops和AdamO的出色回答。他们的回答使我意识到线性回归具有更简洁的表示法的另一个原因是因为规范的定义封装了平方和或。但是在逻辑损失中,没有这样的定义,这使表示法有点复杂。ee

Answers:


18

在线性回归中,用于估计x的最大化似然估计(MLE)解决方案具有以下闭合形式的解决方案(假设A是具有完整列秩的矩阵):

x^lin=argminxAxb22=(ATA)1ATb

这被理解为“找到使目标函数最小化的xAxb22。关于代表这样的线性回归的目标函数的好处是,我们可以把一切都在矩阵符号,解决了X的手。正如Alex R.所提到的,实际上,我们通常不直接考虑A T A 1,因为它在计算上效率低下,并且A经常不符合完整等级标准。相反,我们转向Moore-Penrose伪逆x^lin(ATA)1A。计算上求解伪逆的细节可能涉及Cholesky分解或奇异值分解。

或者,用于估计逻辑回归中系数的MLE解决方案是:

x^log=argminxi=1Ny(i)log(1+exTa(i))+(1y(i))log(1+exTa(i))

其中(假设每个数据样本按行存储):

x是向量,表示回归系数

a(i)是一个矢量表示ith样品/行中的数据矩阵A

y(i)是一个标量{0,1},以及ith对应于标签ith样品

N是数据样本数/数据矩阵A的行数。

再次,这被理解为“找到使目标函数最小的x ”。

如果你愿意,你可以把它更进了一步,并表示X日志在矩阵符号如下:x^log

x^log=argminx[1(1y(1))1(1y(N))][log(1+exTa(1))...log(1+exTa(N))log(1+exTa(1))...log(1+exTa(N))]

but you don't gain anything from doing this. Logistic regression does not have a closed form solution and does not gain the same benefits as linear regression does by representing it in matrix notation. To solve for x^log estimation techniques such as gradient descent and the Newton-Raphson method are used. Through using some of these techniques (i.e. Newton-Raphson), x^log is approximated and is represented in matrix notation (see link provided by Alex R.).


Great. Thanks. I think the reason we do not have something like solving AAx=Ab is the reason we do not take that step more to make the matrix notation and avoid sum symbol.
Haitao Du

We do have some advantage of taking one step further, making it into matrix multiplication would make the code simpler, and in many platforms such as matlab, for loop with sum over all data, is much slower than matrix operations.
Haitao Du

5
@hxd1011: Just a small comment: reducing to matrix equations is not always wise. In the case of ATAx=ATb, you shouldn't actually try looking for matrix inverse ATA, but rather do something like a Cholesky decomposition which will be much faster and more numerically stable. For logistic regression, there are a bunch of different iteration schemes which do indeed use matrix computations. For a great review see here: research.microsoft.com/en-us/um/people/minka/papers/logreg/…
Alex R.

1
@AlexR. thank you very much. I learned that using normal equation will make the matrix conditional number squared. And QR or Cholesky would be much better. Your link is great, such review with numerical methods is always what I wanted.
Haitao Du

15

@joceratops answer focuses on the optimization problem of maximum likelihood for estimation. This is indeed a flexible approach that is amenable to many types of problems. For estimating most models, including linear and logistic regression models, there is another general approach that is based on the method of moments estimation.

The linear regression estimator can also be formulated as the root to the estimating equation:

0=XT(YXβ)

In this regard β is seen as the value which retrieves an average residual of 0. It needn't rely on any underlying probability model to have this interpretation. It is, however, interesting to go about deriving the score equations for a normal likelihood, you will see indeed that they take exactly the form displayed above. Maximizing the likelihood of regular exponential family for a linear model (e.g. linear or logistic regression) is equivalent to obtaining solutions to their score equations.

0=i=1nSi(α,β)=βlogL(β,α,X,Y)=XT(Yg(Xβ))

Where Yi has expected value g(Xiβ). In GLM estimation, g is said to be the inverse of a link function. In normal likelihood equations, g1 is the identity function, and in logistic regression g1 is the logit function. A more general approach would be to require 0=i=1nYg(Xiβ) which allows for model misspecification.

Additionally, it is interesting to note that for regular exponential families, g(Xβ)β=V(g(Xβ)) which is called a mean-variance relationship. Indeed for logistic regression, the mean variance relationship is such that the mean p=g(Xβ) is related to the variance by var(Yi)=pi(1pi). This suggests an interpretation of a model misspecified GLM as being one which gives a 0 average Pearson residual. This further suggests a generalization to allow non-proportional functional mean derivatives and mean-variance relationships.

A generalized estimating equation approach would specify linear models in the following way:

0=g(Xβ)βV1(Yg(Xβ))

With V a matrix of variances based on the fitted value (mean) given by g(Xβ). This approach to estimation allows one to pick a link function and mean variance relationship as with GLMs.

In logistic regression g would be the inverse logit, and Vii would be given by g(Xiβ)(1g(Xβ)). The solutions to this estimating equation, obtained by Newton-Raphson, will yield the β obtained from logistic regression. However a somewhat broader class of models is estimable under a similar framework. For instance, the link function can be taken to be the log of the linear predictor so that the regression coefficients are relative risks and not odds ratios. Which--given the well documented pitfalls of interpreting ORs as RRs--behooves me to ask why anyone fits logistic regression models at all anymore.


1
+1 great answer. formulate it as a root finding on derivative is really new for me. and the second equation is really concise.
Haitao Du
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.