What is ML? Supervised, Unsupervised and Reinforcement Learning
with interactive examples, datasets and learning visuals
What machine learning is and how it differs from traditional programming.
Supervised, unsupervised and reinforcement learning with examples.
Interactive Celsius → Fahrenheit regression and parameter tuning for w and b.
Students already meet ML many times before they reach the classroom.
The phone recognizes a face or fingerprint from patterns learned earlier.
Maps estimate traffic and suggest a route using previous and live movement data.
Spam filters classify emails using words, sender behavior and past examples.
Video and shopping apps suggest content based on similar user behavior.
Fraud detection learns unusual transaction patterns and flags risky activity.
Learning platforms recommend exercises based on previous mistakes and performance.
Clinical AI can help prioritize cases, detect patterns in images or support risk scoring.
Crop disease detection can use leaf images and weather data to support decisions.
Traffic prediction estimates travel time from previous journeys and current road signals.
Feeds rank posts using interests, engagement history and similarity to other content.
Story point: If you already know the formula, do not force ML.
Story point: If examples are easier than rules, ML becomes useful.
Scenario 1: Convert Celsius to Fahrenheit.
Scenario 2: Detect whether an email is spam from words, sender behavior and previous examples.
Machine learning is a way to build systems that improve their behavior from examples, data, feedback or experience.
Instead of writing every rule manually, we provide data and let an algorithm learn a useful pattern.
Input dataLearning algorithmModelPrediction
Human writes the exact rule:
Best when the domain rule is already known and simple.
Computer sees examples and learns a model:
Best when the rule is unknown, complex or expensive to code by hand.
We start with Celsius → Fahrenheit because students can verify the answer using a formula.
Then we hide the formula and ask a model to learn the relationship only from training data.
This creates a safe first ML example: students see both the real rule and the learned approximation.
Learn from labeled examples where each input has a known target output.
Examples: exam pass/fail, Celsius → Fahrenheit, house price prediction.
Find hidden structure in data without labels.
Examples: customer grouping, topic discovery, anomaly detection.
Learn by acting and receiving rewards or penalties.
Examples: game playing, robot navigation, adaptive control.
Supervised learning needs labeled data: each input already has a correct answer.
The algorithm receives data without labels and tries to discover structure by itself.
Output is not a known answer label; it is a discovered pattern.
An agent interacts with an environment, takes actions and receives rewards.
The goal is not one correct label, but maximizing long-term reward.
Which ML approach is being used?
A system groups customers based only on their shopping behavior, without any category labels.
Input x: what we know before prediction.
Output y: what we want to predict.
Dataset: many examples of (x, y).
Model: a function that maps x to y.
Loss: how wrong the prediction is.
Learning algorithm: adjusts the model to reduce error.
| Celsius C | Formula F | Measured F |
|---|---|---|
| -40 | -40.0 | -40.0 |
| -20 | -4.0 | -3.2 |
| -10 | 14.0 | 13.7 |
| 0 | 32.0 | 32.4 |
| 10 | 50.0 | 49.5 |
| 20 | 68.0 | 68.2 |
| 30 | 86.0 | 86.6 |
| 37 | 98.6 | 98.5 |
| 40 | 104.0 | 104.0 |
| 50 | 122.0 | 121.3 |
| 75 | 167.0 | 167.5 |
| 100 | 212.0 | 211.6 |
Given Celsius values, learn the relationship that predicts Fahrenheit values.
Here, Celsius is the input x and Fahrenheit is the output y.
The “measured” column adds tiny noise to simulate real sensor readings and a realistic learning problem.
In all supervised tasks, the training set contains both inputs and correct outputs.
The exact input features can change, but the learning workflow remains similar.
We choose a simple model:
The learning algorithm searches for the best values of w and b.
After training, the model learned:
ŷ = 1.797C + 32.110
Mean absolute error = 0.375 °F | Mean squared error = 0.191
Blue points = training data, red line = your current model line.
As you move the sliders, watch the line rotate and shift. Better values of w and b reduce the prediction error.
import numpy as np
from sklearn.linear_model import LinearRegression
C = np.array([-40, -20, -10, 0, 10, 20, 30, 37, 40, 50, 75, 100]).reshape(-1, 1)
F = np.array([-40.0, -3.2, 13.7, 32.4, 49.5, 68.2, 86.6, 98.5, 104.0, 121.3, 167.5, 211.6])
model = LinearRegression()
model.fit(C, F)
print("slope:", model.coef_[0])
print("intercept:", model.intercept_)
print("Prediction for 25°C:", model.predict([[25]])[0])
Move the slider and compare both predictions.
Formula uses exact domain knowledge. ML estimates the relationship from examples.
If a model is trained only on temperatures between 0°C and 40°C, should we fully trust its prediction for 300°C?
For Celsius → Fahrenheit, the exact mathematical rule is known, so traditional programming is enough and often better.
For medical diagnosis, fraud detection or image recognition, the rule is difficult to write manually. ML becomes useful because it can learn from examples.
Machine learning uses data to learn a model instead of hand-coding every rule.
Supervised learning learns from labeled data and includes regression and classification.
Unsupervised learning finds hidden structure without labels.
Reinforcement learning learns through interaction, actions and rewards.
A supervised learning problem needs inputs, outputs, dataset, model, loss and a learning algorithm.
In linear regression, changing w changes the slope, and changing b shifts the line up or down.
Next class: Linear Regression and Model Evaluation