Skip to content
GATEiit

GATE DA · Machine Learning

Logistic regression

Logistic regression models the probability of a class with the sigmoid of a linear score, is trained by minimising cross-entropy (maximum likelihood), and gives a linear decision boundary; GATE asks for probabilities, log-odds, losses and gradient steps.

Before you start

This topic comes before: Multi-layer perceptron and feed-forward neural networks

Concept notes

1. The model: sigmoid of a linear score

For binary labels y∈{0,1}, logistic regression models P(y=1∣x)=σ(z)=11+e−z,z=w⊤x+b.

The sigmoid (logistic) function maps any real z to (0,1):

  • σ(0)=0.5; σ(z)→1 as z→∞ and →0 as z→−∞.
  • Symmetry: σ(−z)=1−σ(z).
  • Derivative: σ′(z)=σ(z)(1−σ(z)), largest at z=0 where it equals 0.25.
  • Inverse (the logit): z=ln⁡p1−p.

So the model says the log-odds are linear in x: ln⁡P(y=1∣x)P(y=0∣x)=w⊤x+b. Increasing feature xj by one unit adds wj to the log-odds, i.e. multiplies the odds by ewj.

Despite the name, it is a classification method: it outputs a probability and you threshold it.

z σ(z) 10.50 −606 z > 0 ⇒ predict 1 z < 0 ⇒ predict 0
The sigmoid: the score z = wᵀx + b is turned into a probability; z = 0 is the decision boundary

2. Decision boundary

With threshold 0.5 the rule is: predict 1 when σ(z)≥0.5, i.e. when w⊤x+b≥0.

  • The decision boundary w⊤x+b=0 is a hyperplane (a line in 2-D), so logistic regression is a linear classifier. w is normal to the boundary and points towards class 1.
  • The distance of x from the boundary is ∣w⊤x+b∣/∥w∥; points far from it get probabilities near 0 or 1.
  • A threshold t≠0.5 moves the boundary to w⊤x+b=ln⁡t1−t, still parallel to the original.
  • Curved boundaries need non-linear features (e.g. x12,x22); the model stays linear in those features.

Multiclass: softmax regression gives each class k a score zk=wk⊤x+bk and P(y=k∣x)=ezk∑j=1Kezj. With K=2 this reduces to the sigmoid of z1−z2. Adding the same constant to every zk does not change the probabilities.

3. Training: maximum likelihood and cross-entropy

With pi=σ(w⊤xi+b), the likelihood of the labels is ∏ipiyi(1−pi)1−yi. Maximising it is the same as minimising the negative log-likelihood, also called binary cross-entropy or log loss: J(w,b)=−∑i=1n[ yiln⁡pi+(1−yi)ln⁡(1−pi) ].

  • A point with y=1 costs −ln⁡p; a confident wrong prediction (p→0) costs a lot.
  • J is convex in (w,b), so any local minimum is global. (Squared error with a sigmoid is not convex, which is one reason it is not used.)
  • There is no closed-form solution; use gradient descent or Newton's method.

The gradient has the same neat form as in linear regression: ∇wJ=∑i(pi−yi) xi,∂J∂b=∑i(pi−yi). A gradient descent step with learning rate η is w←w−η∑i(pi−yi)xi.

If the classes are linearly separable, the unregularised likelihood keeps improving as ∥w∥→∞, so the weights diverge. Adding an L2 penalty λ∥w∥2 fixes this and reduces overfitting.

4. Logistic regression compared

Linear regression Logistic regression
Target real y y∈{0,1}
Output w⊤x+b σ(w⊤x+b)∈(0,1)
Loss squared error cross-entropy
Solution closed form (normal equations) iterative (convex)
Gradient ∑(y^i−yi)xi ∑(pi−yi)xi

Against other classifiers:

  • vs LDA: both give linear boundaries. LDA is generative and assumes Gaussian classes with shared covariance; logistic regression is discriminative and makes no assumption about P(x∣y), so it is more robust when that assumption fails.
  • vs SVM: both linear; SVM minimises hinge loss and cares only about points near the boundary, while logistic regression uses every point and gives calibrated probabilities.
  • vs perceptron: a single sigmoid neuron trained with cross-entropy is logistic regression; an MLP stacks many of them.

Use logistic regression when you need probabilities, interpretable coefficients (odds ratios) and a linear boundary is adequate.

Formulas to remember

Sigmoid
σ(z)=11+e−z
Sigmoid properties
σ(−z)=1−σ(z),σ′(z)=σ(z) (1−σ(z))
Log-odds (logit)
ln⁡p1−p=w⊤x+b
Binary cross-entropyNatural log unless stated
J=−∑i[yiln⁡pi+(1−yi)ln⁡(1−pi)]
Gradient
∇wJ=∑i(pi−yi) xi
Softmax
P(y=k∣x)=ezk∑jezj

Common mistakes

  • Calling logistic regression a regression method for real targets; it is a classifier that outputs probabilities.
  • Saying a coefficient changes the probability by wj; it changes the log-odds by wj and the odds by a factor ewj.
  • Expecting a closed-form solution; training is iterative even though the loss is convex.
  • Using log⁡10 or log⁡2 in cross-entropy when the question means the natural log, or the reverse.
  • Thinking the decision boundary is curved because the sigmoid is curved; at any fixed threshold the boundary is a hyperplane.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Predicting a probability

numerical

A logistic model has w=(2,−1) and b=−1. Find P(y=1) for xA=(1,1) and xB=(2,1), and classify both with threshold 0.5.

  1. Step 1: Compute the scores.

    Try it on paper first.

Example 2: Reading coefficients as odds ratios

numerical

In a loan model the coefficient of 'number of late payments' is 0.7. A customer currently has P(default)=0.2. What happens to the odds and the probability after one more late payment?

  1. Step 1: Find the current odds and log-odds.

    Try it on paper first.

Example 3: One gradient descent step

numerical

One training point x=2, y=1. Start at w=0, b=0 with learning rate η=0.1. Do one gradient descent step on the cross-entropy loss.

  1. Step 1: Find the current prediction.

    Try it on paper first.

Example 4: Why not squared error?

conceptual

Give two reasons logistic regression is trained with cross-entropy rather than squared error between y and σ(z).

  1. Step 1: Think about the shape of the loss.

    Try it on paper first.

Previous year questions

1 official GATE DA question on this topic, newest first.

Practise these 1 PYQs →

Topic test

9 questions: up to 1 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.