Logistic Regression — ML Technical Interview Questions & Answers
A linear model for binary classification problems.
Logistic Regression
- Simple meaning: Despite the name, logistic regression is classification. It outputs a probability of “pass” (or spam), then you pick a threshold (often 0.5) to say yes/no.
- Picture: hours studied → P(pass). Sigmoid squashes any number into 0..1. Asha 2 hours → 0.18 fail. Kabir 6 hours → 0.91 pass.
- sklearn: LogisticRegression().fit then predict or predict_proba. On imbalanced pass/fail, don’t brag accuracy — use precision/recall/F1.
- Trap: “logistic is regression because of the name”. Trap: 95% pass dummy accuracy.
Technical Interview Tip: Name says regression, job is classification. Probability + threshold.
Code Examples for Logistic Regression
Logistic Regression — working example
def majority_vote(labels):
return max(set(labels), key=labels.count)
neighbors = [1, 1, 0, 1, 0]
print(majority_vote(neighbors)) # kNN-style vote
# Logistic idea: score → probability via sigmoid
def sigmoid(z):
return 1 / (1 + 2.718281828 ** (-z))
print(round(sigmoid(0.0), 3), round(sigmoid(2.0), 3))Logistic Regression — classifiers map features to labels; kNN votes neighbors; logistic uses a sigmoid probability.
How to Explain Logistic Regression to an Interviewer
Is logistic regression for numbers or classes?
Classes Probability of a label
What is the sigmoid for?
Squash to a probability 0 to 1