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 Hours | Result |
|---|---|
| 1 | Fail |
| 2 | Fail |
| 3 | Fail |
| 5 | Pass |
| 6 | Pass |
| 8 | Pass |
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:
| Probability | Prediction |
|---|---|
| 0.10 | Fail |
| 0.25 | Fail |
| 0.45 | Fail |
| 0.50 | Decision boundary |
| 0.70 | Pass |
| 0.90 | Pass |
| 0.98 | Pass |
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 Regression | Logistic Regression |
|---|---|
| Used mainly for regression | Used mainly for classification |
| Predicts numerical values | Predicts probabilities/classes |
| Output can be any continuous value | Output is between 0 and 1 |
| Uses a straight-line equation | Uses sigmoid function |
| Example: House price | Example: Buy/Don’t Buy |
| Example: Sales prediction | Example: 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.
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
- Simple and easy to understand
- Easy to implement.
- Fast for many classification problems.
- Gives probability as output.
- Works well when classes are approximately linearly separable.
- The coefficients can provide useful information about feature influence.
12. Disadvantages
- It may not perform well with complex non-linear relationships.
- It can be affected by outliers.
- Features may need proper scaling depending on the problem.
- It assumes a suitable relationship between the features and the log-odds.
- 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
