Tool for HR, Hiring Managers, and the Leadership Team

What is Logistic Regression?

What is Logistic Regression? 

Logistic Regression is a Supervised Machine Learning algorithm mainly used for classification problems.

Even though the name contains “Regression”, it is actually used to predict categories/classes, such as:

  • Spam or Not Spam

  • Fraud or Not Fraud

  • Pass or Fail

  • Disease or No Disease

Simple Definition

Logistic Regression predicts the probability that an input belongs to a particular class.

The output is usually:

  • 0 → Negative class

  • 1 → Positive class

Example:

  • 0 = Fail

  • 1 = Pass

Real-World Example

Suppose we want to predict whether a student will pass an exam based on study hours.

Study Hours Result
1 Fail
2 Fail
3 Fail
5 Pass
6 Pass
8 Pass

Now if a student studies 4.5 hours, Logistic Regression predicts the probability of passing.

Example output:

  • Probability of Pass = 0.82

  • Since 0.82 > 0.5 → Predict Pass

Why Not Linear Regression?

Linear Regression can produce outputs like:

  • -2

  • 120

But probabilities should only be between:

  • 0 and 1

So Logistic Regression uses a special function called the Sigmoid Function.

Sigmoid Function

The sigmoid converts any value into a range between 0 and 1.

Output Behavior

  • Very large positive value → close to 1

  • Very large negative value → close to 0

  • Middle value → around 0.5

How Logistic Regression Works

Step-by-Step

1. Take Input Features

Example:

  • Study hours

  • Attendance

  • Assignment score

2. Calculate Weighted Sum

z=w_1x_1+w_2x_2+b

3. Apply Sigmoid Function

Converts result into probability.

4. Apply Threshold

Usually:

  • Probability ≥ 0.5 → Class 1

  • Probability < 0.5 → Class 0

Decision Boundary

Logistic Regression creates a decision boundary that separates classes.

Example:

  • Left side → Fail

  • Right side → Pass

For a single feature problem, the boundary is usually a straight line.

Types of Logistic Regression

1. Binary Logistic Regression

Two classes only.

Examples:

  • Yes/No

  • True/False

  • Fraud/Not Fraud

2. Multiclass Logistic Regression

More than two classes.

Examples:

  • Predict Grade: A/B/C

  • Recognize animal type

Advantages

Simple and easy to understand
Fast training
Works well for linearly separable data
Outputs probabilities
Good baseline classification model

Disadvantages

Not good for complex nonlinear relationships
Sensitive to outliers
Can underperform on very large complex datasets

Common Interview Questions

Q1. Why is it called regression if it is used for classification?

Because it estimates probabilities using a regression-like equation before applying classification.

Q2. What is the output of Logistic Regression?

Probability values between 0 and 1.

Q3. What function is used in Logistic Regression?

Sigmoid (Logistic) Function.

Q4. What is the difference between Linear Regression and Logistic Regression?

Linear Regression Logistic Regression
Used for prediction of continuous values Used for classification
Output can be any value Output between 0 and 1
Uses straight line Uses sigmoid curve

Simple Interview Answer

Logistic Regression is a supervised machine learning algorithm used for classification problems.
It predicts the probability that an input belongs to a particular class using the sigmoid function.
Common use cases include spam detection, fraud detection, and disease prediction.

Python Example

from sklearn.linear_model import LogisticRegression

X = [[1], [2], [3], [5], [6], [8]]
y = [0, 0, 0, 1, 1, 1]

model = LogisticRegression()
model.fit(X, y)

prediction = model.predict([[4.5]])

print(prediction)

Interview Tip

When explaining Logistic Regression in interviews:

  1. First say it is a classification algorithm

  2. Mention probability prediction

  3. Explain sigmoid function

  4. Give a simple real-world example

  5. Mention binary classification use cases

That structure makes the answer strong and easy to follow.