Logistic_Regression

Logistic Regression

Logistic regression is an approach to classification problem rather than a quantative prediction. More confusingly speeking, logistic regression is NOT used to solve regression problems.

Typically, the logistic regression is used to solve binary classification problem, that is, the output only have two levels, high or low, good or bad, be or not be, etc..

  • Pros
    • Easy to understand and complete in code;
    • Requires little on computing power.
  • Cons
    • Easily get overfitting
    • Low accuracy at rapid growth part

Model

Sigmoid Function

In classification problem, we want the model to accept every input and gives out a possibility of a certain class that the inputs indicates. Unit step function is a choice but it is hard for us to handle the step. Sigmoid function has similar property but a much gentle way of the step.

σ(z)=11+ez

and the curve shows as
sigmoid function

The sigmoid function has a good property on derivative.

σ(z)=σ(z)(1σ(z))

Note that σ(z) can be recognized as the posibility for one certain class.

Decision Boundary

In most cases, we treat two classes with equal significance and therefore, we use 0.5 as our decision boundary. That is, σ(z)0.5y^=1 and σ(z)<0.5y^=0

The Logistic Model

The input of sigmoid function is denoted as z and given as following,

z=θ0+j=1nθix(i)j

Combining equation (1) and (2) and take logarithm of both side we could get

log(σ(x(i))1σ(x(i)))=θ0+j=1nθix(i)j

where x⃗ =(1,x1,x2,...,xn)T . The left hand side is called log-odds or logit.

Therefore, the logistic regression can be modelled as,

y^(i)=σ(θTx(i))=11+eθ0+j=1nθjx(i)j

Coefficient Estimation

In classification problem, we should expect the cost as large as possible if the classification is wrong. The pictures below gives a brief view of the cost.

By using a small math trick, we could combine the two situation above together. Cost function could be shown as,

J(θ)=1m(yTlog(y^)(1y)Tlog(1y^))

where y and y^ are true and predicted vector. We can find that when one element in y is 0, then we will messure how far is the corresponding esitimated value from 0 and vice versa. Only one item in J(θ) exists given a certain y(i) . Logarithm is used to avoid computation among large numbers.

Gradient Descent

Overall, the gradient descent algorithm could represented as

θ:=θαJ(θ)

If we use the gradient descent method to optimize the coefficients, following are the steps.

J(θ)θj=1mi=1m(y^(i)y(i))x(i)j
and
J(θ)θ=1mXT(y^y⃗ )

In every circle, we update θ by

θ:=θαmJ(θ)θ

Possible Extension

Logit

Recall the equation (3), we get log(σ(x(i))1σ(x(i))) . This is so called logit, or log-odds. For more information, see wikipedia.

Linear Discriminant Analysis

Though there are several extension of logistic regression to adjust it to multi-class classification problem, Linear Discriminant Analysis is more popular on solving such problems. For more information about LNA, click here. For more information about Multicalss Classification Logistic Regression, see wikipedia

Other Logistic Regressions

Potential Problems

Overfitting

Overfitting problems is common in cost function in logistic regression model.

Following image shows underfit, fit, and overfit in sequence.

To overcome the overfit problem, there are two possible ways.

Reduce the number of features.

This may casue information lost, the features left should be carefully selected.

Rugularization

Keep all the features and add a punishment item to cost function J(θ) . Usually, we use L2 norm as the punishment. The cost function changes to

J(θ)=12m(i=1m(y^(i)y(i))2+λj=1nθ2j)

and corresponding update of theta changes to

θj:=θjαm(i=1m(y^(i)y(i))x(i)j+λθj)

where λ is punishment coeffiencient. A larger λ punish the model harder and it may lead to underfitting problem, so a proper selection of λ is necessary.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值