Skip to content
Home » Logistic Regression

Logistic Regression

1. Definition

Logistic Regression is a supervised machine learning algorithm mainly used for classification problems.

It predicts the probability of an outcome and then converts that probability into a class such as:

  • Yes / No
  • Pass / Fail
  • Spam / Not Spam
  • Buy / Don’t Buy
  • Disease / No Disease

Important: Although its name contains “Regression”, Logistic Regression is mainly used for classification.


2. Simple Example

Suppose we want to predict whether a student will Pass or Fail based on study hours.

Study HoursResult
1Fail
2Fail
3Fail
5Pass
6Pass
8Pass

Logistic Regression learns the relationship between study hours and the probability of passing.

For a new student who studies 6 hours, it might predict:\[ P(Pass)=0.90 \]

So:

90% probability of Pass → Pass


3. Why Do We Need Logistic Regression?

Linear Regression gives continuous values.

For example:\[ y = 20 + 5x \]

The output could be:

20, 25, 30, 35, 40...

But in classification we need:

0 = Fail
1 = Pass

We therefore need a function that converts any value into a probability between 0 and 1.

Logistic Regression uses the Sigmoid Function.


4. Sigmoid Function

The sigmoid function is:\[ P(y=1)=\frac{1}{1+e^{-z}} \]

where:\[ z=b_0+b_1x \]

So the complete equation is:\[ P(y=1)=\frac{1}{1+e^{-(b_0+b_1x)}} \]

The sigmoid function produces values between 0 and 1.

Simple idea

Input
  ↓
Linear Equation
  ↓
Sigmoid Function
  ↓
Probability (0 to 1)
  ↓
Decision
  ↓
Class 0 or Class 1

5. Sigmoid Curve

The sigmoid function has an S-shaped curve.Learn more

The important point is that the output is always between:\[ 0 \leq P \leq 1 \]

For example:

ProbabilityPrediction
0.10Fail
0.25Fail
0.45Fail
0.50Decision boundary
0.70Pass
0.90Pass
0.98Pass

Usually, 0.5 is used as the threshold.


6. How Logistic Regression Works

The process is:

Step 1: Take input data

For example:

Study Hours = 6
Attendance = 85%

Step 2: Calculate linear value

\[ z=b_0+b_1x \]

For multiple features:\[ z=b_0+b_1x_1+b_2x_2+\cdots+b_nx_n \]

Step 3: Apply sigmoid function

The value of \(z\) is converted into a probability.

For example:\[ P(Pass)=0.85 \]

Step 4: Apply threshold

If threshold = 0.5:

Probability ≥ 0.5 → Class 1
Probability < 0.5 → Class 0

Therefore:

0.85 ≥ 0.5
     ↓
   PASS

7. Binary Logistic Regression

When there are two classes, it is called Binary Logistic Regression.

Example:

0 = No
1 = Yes

Applications:

  • Pass / Fail
  • Spam / Not Spam
  • Buy / Don’t Buy
  • Disease / No Disease

8. Multinomial Logistic Regression

When there are more than two classes, Logistic Regression can also be used in multinomial form.

Example:

Predicting customer preference:

1 → Basic Plan
2 → Standard Plan
3 → Premium Plan

Another example:

Low Risk
Medium Risk
High Risk

9. Logistic Regression vs Linear Regression

Linear RegressionLogistic Regression
Used mainly for regressionUsed mainly for classification
Predicts numerical valuesPredicts probabilities/classes
Output can be any continuous valueOutput is between 0 and 1
Uses a straight-line equationUses sigmoid function
Example: House priceExample: Buy/Don’t Buy
Example: Sales predictionExample: Spam detection

Easy memory:

Linear Regression → Predict a Number

Logistic Regression → Predict a Class


10. Applications

Logistic Regression is widely used in:

Banking

Predict whether a customer will default on a loan.

Marketing

Predict whether a customer will purchase a product.

Email

Predict whether an email is spam or not spam.

Healthcare

Predict whether a patient has a particular disease or not.

Education

Predict whether a student will pass or fail.

Digital Marketing

Predict whether a lead will:

Convert → Yes
Not Convert → No

11. Advantages

  1. Simple and easy to understand
  2. Easy to implement.
  3. Fast for many classification problems.
  4. Gives probability as output.
  5. Works well when classes are approximately linearly separable.
  6. The coefficients can provide useful information about feature influence.

12. Disadvantages

  1. It may not perform well with complex non-linear relationships.
  2. It can be affected by outliers.
  3. Features may need proper scaling depending on the problem.
  4. It assumes a suitable relationship between the features and the log-odds.
  5. Complex problems may require algorithms such as Random Forest or Neural Networks.

13. Exam-Ready Answer

Logistic Regression is a supervised machine learning algorithm used mainly for classification problems. It predicts the probability that an observation belongs to a particular class. It uses the sigmoid function to convert the output of a linear equation into a value between 0 and 1. Usually, a probability of 0.5 or more is classified as class 1, while a probability below 0.5 is classified as class 0. Logistic Regression is used in spam detection, disease prediction, customer purchase prediction, loan approval and pass/fail prediction.

Formula

\[ P(y=1)=\frac{1}{1+e^{-(b_0+b_1x)}} \]

Remember:

Logistic Regression = Linear Equation + Sigmoid Function + Probability + Classification