1 of 10

LESSON 01

Machine

Learning

CLASSIFICATION

SERIES

Logistic

Regression

Basics of Classification

Understanding how machines learn to categorize

data into discrete classes using probabilities

Introduction to Machine Learning | Logistic Regression

2 of 10

What We'll Cover Today

01

What is Classification?

Binary vs multi-class, real-world examples

02

Linear vs Logistic Regression

Key differences & why linear fails for classification

03

The Sigmoid Function

Mapping outputs to probabilities [0, 1]

04

Decision Boundary

How the model separates classes

05

Cost Function & Training

Log-loss and gradient descent basics

06

Evaluation Metrics

Accuracy, precision, recall, confusion matrix

3 of 10

What is Classification?

Classification: Predicting which category (class) a data point belongs to.

Binary Classification Examples

๐Ÿ“ง

Email

Spam

Not Spam

Output: 0 or 1

๐Ÿฅ

Diagnosis

Disease

Healthy

Output: 0 or 1

๐Ÿ’ณ

Transaction

Fraud

Legit

Output: 0 or 1

โœ…

Loan

Approved

Denied

Output: 0 or 1

๐Ÿ’ก Key Insight: Unlike regression (predicting a number), classification predicts a discrete label.

4 of 10

Linear vs Logistic Regression

Linear Regression

Logistic Regression

Output Type

Any real number (โˆ’โˆž to +โˆž)

Probability (0 to 1)

Goal

Predict continuous values

Predict class probability

Output Function

y = mx + b (linear)

y = ฯƒ(mx + b) (sigmoid)

Example Use

Predict house price ($)

Predict spam? (yes/no)

Decision

No threshold needed

Threshold at 0.5 โ†’ class

Loss Function

Mean Squared Error (MSE)

Binary Cross-Entropy

โš ๏ธ Why linear fails for classification: It can predict values outside [0,1], which can't represent probabilities!

5 of 10

The Sigmoid Function

ฯƒ(z) =

1

1 + e

-z

where z = wx + b

Key Properties:

  • Output always between 0 and 1
  • S-shaped (sigmoidal) curve
  • ฯƒ(0) = 0.5 (decision boundary)
  • As z โ†’ +โˆž, ฯƒ โ†’ 1
  • As z โ†’ โˆ’โˆž, ฯƒ โ†’ 0

Probability โ†’ Class

P โ‰ฅ 0.5 โ†’ Class 1 โœ“

P < 0.5 โ†’ Class 0 โœ—

Threshold can be adjusted

based on use case

6 of 10

Decision Boundary

Feature Space Visualization

Feature Xโ‚ โ†’

Feature Xโ‚‚

Decision

Boundary

ฯƒ(z) = 0.5

Class 0 (Negative)

Class 1 (Positive)

How It Works

1

Model learns weights

(w) and bias (b)

2

Computes z = wยทx + b

for each data point

3

Applies sigmoid:

P = ฯƒ(z)

4

If P โ‰ฅ 0.5 โ†’ Class 1

If P < 0.5 โ†’ Class 0

7 of 10

Cost Function & Training

โŒ Why not use MSE (Mean Squared Error)? With sigmoid, MSE creates a non-convex loss โ€” prone to many local minima!

Binary Cross-Entropy (Log Loss):

J(w,b) = โˆ’(1/m) ฮฃ [ yยทlog(ลท) + (1โˆ’y)ยทlog(1โˆ’ลท) ]

y = 1 (positive class)

Loss = โˆ’log(ลท)

Push ลท โ†’ 1 to minimize loss

y = 0 (negative class)

Loss = โˆ’log(1โˆ’ลท)

Push ลท โ†’ 0 to minimize loss

Gradient Descent

w := w โˆ’ ฮฑ ยท โˆ‚J/โˆ‚w

Iteratively find optimal weights

8 of 10

Evaluation Metrics

Confusion Matrix

Predicted โ†’

Predicted 0

Predicted 1

Actual โ†“

Actual 0

Actual 1

TN

True Neg

FP

False Pos

FN

False Neg

TP

True Pos

Key Metrics

Accuracy

(TP + TN) / Total

Overall correctness

Precision

TP / (TP + FP)

Of predicted positives, how many are correct

Recall

TP / (TP + FN)

Of actual positives, how many detected

F1-Score

2 ร— (P ร— R) / (P + R)

Harmonic mean of precision & recall

9 of 10

Visual Comparison: Linear vs Logistic

โŒ Linear Regression for Classification

Problem: values go outside [0,1]!

โœ… Logistic Regression for Classification

Always stays between 0 and 1 โœ“

10 of 10

Key Takeaways

Logistic Regression โ€” Lecture 05 Summary

๐ŸŽฏ

#01

Logistic regression predicts class probabilities (0 to 1), not continuous values.

ใ€ฝ๏ธ

#02

The sigmoid function maps any real number to a probability between 0 and 1.

โš ๏ธ

#03

Linear regression fails for classification โ€” it can output values outside [0, 1].

๐Ÿ“

#04

Decision boundary at threshold 0.5 separates the two classes in feature space.

๐Ÿ“‰

#05

Binary cross-entropy (log loss) is the correct loss function for logistic regression.

๐Ÿ“Š

#06

Accuracy, precision, recall & F1-score are used to evaluate classification models.

Next Lesson โ†’ Multiclass Classification & Softmax | Practice: Implement logistic regression from scratch!