Logistic Regression

Sigmoid/Logistic function

g(z)=11+e−zg(z) = {1 \over 1+e^{-z}}

Hypothesis

hθ(x)=g(θ⋅x)=11+e−θ⋅xh_\theta(x) = g(\theta \cdot x) = {1 \over 1 + e^{-\theta \cdot x}}
  • y=1y=1 if hθ(x)≥0.5h_\theta(x) \ge 0.5 (i.e. θ⋅x≥0\theta \cdot x \ge 0)
  • y=0y=0 if hθ(x)<0.5h_\theta(x) < 0.5 (i.e. θ⋅x<0\theta \cdot x < 0)

Logistic Regression Cost Function

J(θ)=−1m[∑i=1myilog⁡hθ(xi)+(1−yi)log⁡(1−hθ(xi))]J(\theta) = - {1 \over m} [\sum_{i=1}^m y_i \log h_\theta(x_i) + (1-y_i) \log(1-h_\theta(x_i))]

Gradient Descent

min⁡θJ(θ)\min_\theta J(\theta)

Repeat: simultaneously update all θj\theta_j

θj:=θj−α∂∂θjJ(θ)\theta_j:=\theta_j - \alpha {\partial \over \partial \theta_j} J(\theta) θj:=θj−α∑i=1m(hθ(xi)−yi)xi\theta_j:=\theta_j - \alpha \sum_{i=1}^m (h_\theta(x_i) - y_i)x_i

Regularization

J(θ)=−1m[∑i=1myilog⁡hθ(xi)+(1−yi)log⁡(1−hθ(xi))]+λ2m∑i=1nθj2J(\theta) = - {1 \over m} [\sum_{i=1}^m y_i \log h_{\theta(x_i)} + (1-y_i) \log(1-h_\theta(x_i))] + {\lambda \over 2m} \sum_{i=1}^n \theta_j^2