Logistic Regression
Desprite the name it's a classification algorithm
Model function (Hypothesis)
We want a model function that is 0≤hθ(x)≤1
hθ(x)=g(θTx)=1+e−θTx1
-
g is the Sigmoid function or Logistic function
g(z)=1+e−z1

-
This value is the estimated probablity that y=1 on the given x
hθ(x)=P(y=1∣x;θ)
- "The probability that y=1, given x, parametrized by θ"
-
We say y=1 when hθ(x)≥0.5, i.e. z=θTx≥0
Cost Function
We cannot use the same cost function as with Linear regression, since it will not be convex (i.e. it will have local minima)
So we use:
J(θ)=m1∑i=1mCost(hθ(x(i)),y(i))
With:
-
Cost(hθ(x),y)=−log(hθ(x)) if y = 1

-
Cost(hθ(x),y)=−log(1−hθ(x)) if y = 0

Combined into one function that is:
Cost(hθ(x),y)=−y∗log(hθ(x))−(1−y)∗log(1−hθ(x))
This becomes:
J(θ)=−m1∑i=1m(y(i)∗log(hθ(x(i)))+(1−y(i))∗log(1−hθ(x(i))))
(Batch) Gradient Descent Algorithm
θj:=θj−αm1∑i=1m(hθ(x(i))−y(i))∗xj(i)
So
∂θj∂J(θ)=m1∑i=1m(hθ(x(i))−y(i))∗xj(i)