Processing math: 100%

Building Logistic Regression Model from Linear Regression Model

A model called logistic regression is introduced in Week 3 of Machine Learning course taught by Andrew Ng. This post tries to explain how to obtain logistic regression model from linear regression model which has been explained in Week 1 and Week 2 of the course. Therefore, I recommend all readers for studying Week 1 and Week 2 before reading this post.

Week 1 of the course shows that linear regression model has the capability to solve classification problem with prediction model (hypothesis) as follows:

hθ(x)=θTx

with θ=[θ0θ1θ2θn]T is called parameter model and x=[1x1x2xn]T is a test example whose y we would like to predict.

The question arises as follows:

How can we derive logistic regression model from linear regression model?

As we already know that hθ(x) in logistic regression has a range of values between 0 and 1; on the other hand, hθ(x) in linear regression has a range of values between and . Therefore, hθ(x) which belongs to logistic regression needs to be converted into <hθ(x)<. Moreover, after the conversion is done, the new hθ(x) shall be substituted into Equation (1).

Let us start by converting hθ(x) which belongs to logistic regression and then substitute the new hθ(x) into Equation (1).

0<hθ(x)<10<hθ(x)1hθ(x)<<log(hθ(x)1hθ(x))the new hθ(x)<.

hθ(x)1hθ(x) in Equation (2) is called odds ratio and log(hθ(x)1hθ(x)) in Equation (3) is named as logit function (Raschka & Mirjalili, 2017).

Now that the new hθ(x) has the range of values between <hθ(x)<, this new hθ(x) can be substituted into Equation (1) as follows:

log(hθ(x)1hθ(x))=θTxelog(hθ(x)1hθ(x))=eθTxhθ(x)1hθ(x)=eθTxhθ(x)=eθTxhθ(x)eθTxhθ(x)+hθ(x)eθTx=eθTxhθ(x)(1+eθTx)=eθTxhθ(x)=eθTx1+eθTxhθ(x)=eθTx1+eθTx×eθTxeθTxhθ(x)=11+eθTx.

Accordingly, logistic regression model that we have derived is

hθ(x)=11+eθTx

Logistic regression model in Equation (4) is popularly also called sigmoid function. Finally, we have successfully derived logistic regression model (Equation (4)) from linear regression model (Equation (1)).

References

Raschka, S. and Mirjalili, V. (2017) Python Machine Learning Second Edition. Packt Publishing Ltd. Page 59-60.


Written on August 17, 2019