Skip to main content
AI & Machine Learning•Last Updated : 09 Oct 2026
~45 min read

Supervised Machine Learning

Mathematical foundations of predictive modeling: cost functions (MSE), learning rates, gradient descent parameter updates, Bayes theorem, and Naive Bayes text classification.

What is Machine Learning?

Machine Learning is a subfield of artificial intelligence where computer systems learn mathematical models and predictive rules directly from data, rather than being explicitly hardcoded.

Definition: Machine Learning

A computational system that iteratively learns predictive models h(x) from training data instances without manual rule programming.

Note

Supervised learning relies on labeled training pairs (x, y) to predict outputs for unseen instances. Unsupervised learning analyzes unlabeled data to uncover natural latent clusters.

Supervised Learning Pipeline

In supervised learning, a training set of input-output pairs is fed into a learning algorithm to produce a hypothesis function h that maps new feature vectors x to predicted outputs y.

Example: House Price Prediction (Features to Target)

Input vector x = [Size ft², Bedrooms, Floors, Age] maps to Target Output Y = Price ($1000). For continuous targets, this is Regression; for discrete labels (Yes/No, Spam/Ham), this is Classification.

  1. Instance x(1) = [2104, 5, 1, 45] -> Target Y = $460k
  2. Instance x(2) = [1416, 3, 2, 40] -> Target Y = $232k
  3. Instance x(3) = [1534, 3, 2, 30] -> Target Y = $315k

Feature Vectors & Notation

A feature vector x = [x1, x2, ..., xn] is a structured array of measurable attributes describing a specific sample in the dataset.

Dataset Representation

D = {(x^(1), y^(1)), (x^(2), y^(2)), ..., (x^(m), y^(m))}
Variable Definitions & Term Breakdown:
x^(i)Feature vector of i-th training sample in R^n
y^(i)Target label or ground truth class of i-th sample
h(x)Hypothesis function produced by learning algorithm
X-H-Y FLOWX goes in, H processes, Y comes out

The entire purpose of the learning algorithm is to find the function h that minimizes prediction error on unseen x.

Bayes Theorem — Mathematical Foundations

Bayes Theorem allows us to invert conditional probabilities, calculating the posterior probability of a class given observed features.

Bayes Theorem

P(C | F) = [ P(F | C) * P(C) ] / P(F)
Variable Definitions & Term Breakdown:
P(C | F)Posterior probability of class C given feature vector F (target)
P(F | C)Likelihood of observing feature F given class C
P(C)Prior probability of class C in the dataset
P(F)Evidence (constant marginal probability across all classes)
Tip

Because the denominator P(F) is identical for all classes during a classification query, it can be dropped when finding the argmax class.

The Naïve Bayes Classifier & Independence Assumption

Naïve Bayes makes the simplifying assumption that all input features are conditionally independent given the class label.

Naïve Bayes Optimization Objective

C* = argmax_C [ P(C) * Product_{j=1}^n P(F_j | C) ]
Variable Definitions & Term Breakdown:
argmax_CSelect the class C that yields the highest numeric product
P(C)Count(class C) / Total Samples
P(F_j | C)Count(Feature j has value v within class C) / Count(class C)
Caution

The Conditional Independence Assumption: P(F1, F2, ..., Fn | C) = P(F1|C) * P(F2|C) * ... * P(Fn|C). Although features are rarely 100% independent in real life, Naïve Bayes works remarkably well in practice, especially for text and spam classification.

1-Feature Worked Example: 'Drew' Gender Classification

Consider a dataset of 8 individuals (3 Male, 5 Female). A new person arrives with Name = 'Drew'. What is their most probable gender?

Example: Probability Calculation for Officer Drew

Training data: Male = 3, Female = 5. Drew appears 1 time under Male and 2 times under Female.

  1. P(Male) = 3/8 = 0.375 | P(Female) = 5/8 = 0.625
  2. Likelihood P(Drew | Male) = 1/3 ≈ 0.333
  3. Likelihood P(Drew | Female) = 2/5 = 0.400
  4. Posterior P(Male | Drew) ∝ 1/3 * 3/8 = 1/8 = 0.125 (Normalized: 33.3%)
  5. Posterior P(Female | Drew) ∝ 2/5 * 5/8 = 2/8 = 0.250 (Normalized: 66.7%)
  6. Conclusion: P(Female | Drew) > P(Male | Drew) -> Classified as Female.

Full Worked Example: Play Tennis Dataset ⭐ (Exam Classic)

Given 14 days of weather conditions, classify whether tennis will be played on a day with: Outlook=Sunny, Temp=Cool, Humidity=High, Wind=Strong.

Tennis Posterior Probability Comparison

Score(Yes) = 9/14 * (2/9) * (3/9) * (3/9) * (3/9) = 0.0053 Score(No) = 5/14 * (3/5) * (1/5) * (4/5) * (3/5) = 0.0206
Variable Definitions & Term Breakdown:
Score(No) = 0.0206Significantly larger than Score(Yes) = 0.0053
Normalized P(No)0.0206 / (0.0053 + 0.0206) = 79.5%
Final PredictionPlayTennis = No (Do not play tennis)

Advantages & Limitations of Naïve Bayes

Understanding the strengths and trade-offs of the algorithm for real-world engineering deployments.

Interactive Quiz: Naïve Bayes Predictor

Suggested Quiz
Question 1 of 3

What is the primary assumption made by the Naïve Bayes Classifier?

Python Implementation from Scratch (Tennis Dataset)

PythonNaïve Bayes from Scratch in Python
1# Naive Bayes Classifier - Play Tennis Example
2P_yes = 9 / 14
3P_no = 5 / 14
4
5# Likelihoods for Query: (Outlook=Sunny, Temp=Cool, Hum=High, Wind=Strong)
6# Yes likelihoods:
7P_sunny_yes = 2 / 9
8P_cool_yes = 3 / 9
9P_high_yes = 3 / 9
10P_strong_yes = 3 / 9
11
12# No likelihoods:
13P_sunny_no = 3 / 5
14P_cool_no = 1 / 5
15P_high_no = 4 / 5
16P_strong_no = 3 / 5
17
18score_yes = P_yes * P_sunny_yes * P_cool_yes * P_high_yes * P_strong_yes
19score_no = P_no * P_sunny_no * P_cool_no * P_high_no * P_strong_no
20
21total = score_yes + score_no
22p_yes_norm = score_yes / total
23p_no_norm = score_no / total
24
25print(f"Score Yes: {score_yes:.6f} -> Normalized: {p_yes_norm * 100:.1f}%")
26print(f"Score No: {score_no:.6f} -> Normalized: {p_no_norm * 100:.1f}%")
27print(f"Final Decision: PlayTennis = {'Yes' if score_yes > score_no else 'No'}")
Output
Score Yes: 0.005291 -> Normalized: 20.5%
Score No:  0.020571 -> Normalized: 79.5%
Final Decision: PlayTennis = No
Article Tags:#Machine Learning#Supervised Learning#Naive Bayes#Gradient Descent#Classification
Was this lesson clear and helpful?

Discussion (0)

Sign in to ask questions and reply.
Loading discussion…
Discuss in community