CSE-403 Machine Learning

Introduction to
Machine Learning

What is ML? Supervised, Unsupervised and Reinforcement Learning
with interactive examples, datasets and learning visuals

Md Atikuzzaman
Lecturer
Department of Computer Science & Engineering
atik@cse.green.edu.bd

Today’s Roadmap

1. Foundations

What machine learning is and how it differs from traditional programming.

2. Approaches

Supervised, unsupervised and reinforcement learning with examples.

3. Practice

Interactive Celsius → Fahrenheit regression and parameter tuning for w and b.

A Story: One Morning with Machine Learning

Students already meet ML many times before they reach the classroom.

📱

Phone unlock

The phone recognizes a face or fingerprint from patterns learned earlier.

🚌

Ride or route

Maps estimate traffic and suggest a route using previous and live movement data.

📧

Email filtering

Spam filters classify emails using words, sender behavior and past examples.

🎬

Recommendations

Video and shopping apps suggest content based on similar user behavior.

Daily data→ Pattern learning→ Prediction or decision

Daily Examples of Machine Learning

Banking

Fraud detection learns unusual transaction patterns and flags risky activity.

Education

Learning platforms recommend exercises based on previous mistakes and performance.

Healthcare

Clinical AI can help prioritize cases, detect patterns in images or support risk scoring.

Agriculture

Crop disease detection can use leaf images and weather data to support decisions.

Transport

Traffic prediction estimates travel time from previous journeys and current road signals.

Social media

Feeds rank posts using interests, engagement history and similarity to other content.

When Should We Use Machine Learning?

Use traditional coding when...

  • The rule is clear, stable and easy to write.
  • Exact correctness is required and the logic is known.
  • The problem has few exceptions.
  • Example: Celsius → Fahrenheit conversion.

Story point: If you already know the formula, do not force ML.

Use ML when...

  • The rule is hard to describe manually.
  • There are many examples available.
  • The pattern changes over time.
  • Example: spam detection or image classification.

Story point: If examples are easier than rules, ML becomes useful.

Classroom Decision: Rule or ML?

Scenario 1: Convert Celsius to Fahrenheit.

Scenario 2: Detect whether an email is spam from words, sender behavior and previous examples.

What is Machine Learning?

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

Data + Learning Algorithm → Model

Model + New Input → Prediction

Traditional Programming vs Machine Learning

Traditional conversion

Human writes the exact rule:

F = (C × 9/5) + 32

Best when the domain rule is already known and simple.

ML conversion

Computer sees examples and learns a model:

F ≈ wC + b

Best when the rule is unknown, complex or expensive to code by hand.

Storyline for Today’s Example

Act 1: Known rule

We start with Celsius → Fahrenheit because students can verify the answer using a formula.

F = 1.8C + 32

Act 2: Learn from examples

Then we hide the formula and ask a model to learn the relationship only from training data.

ŷ = wC + b

This creates a safe first ML example: students see both the real rule and the learned approximation.

Three Approaches to Machine Learning

Supervised

Learn from labeled examples where each input has a known target output.

Examples: exam pass/fail, Celsius → Fahrenheit, house price prediction.

Unsupervised

Find hidden structure in data without labels.

Examples: customer grouping, topic discovery, anomaly detection.

Reinforcement

Learn by acting and receiving rewards or penalties.

Examples: game playing, robot navigation, adaptive control.

Supervised Learning: Examples and Visuals

Two common tasks

  • Regression: predict a continuous value such as temperature, salary or house price.
  • Classification: predict a category or class such as pass/fail, spam/not spam, disease/no disease.

Supervised learning needs labeled data: each input already has a correct answer.

Unsupervised Learning: Discovering Hidden Structure

Key idea

The algorithm receives data without labels and tries to discover structure by itself.

  • Grouping similar customers into segments
  • Finding similar documents or topics
  • Detecting unusual or anomalous behavior

Output is not a known answer label; it is a discovered pattern.

Reinforcement Learning: Learn by Trial and Reward

Key idea

An agent interacts with an environment, takes actions and receives rewards.

  • Robot learns to move without falling
  • Game AI learns winning strategies
  • Traffic lights learn better signal timing

The goal is not one correct label, but maximizing long-term reward.

Interactive Check

Which ML approach is being used?

A system groups customers based only on their shopping behavior, without any category labels.

Elements of a Supervised Learning Problem

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.

Dataset: Celsius to Fahrenheit

Celsius CFormula FMeasured F
-40-40.0-40.0
-20-4.0-3.2
-1014.013.7
032.032.4
1050.049.5
2068.068.2
3086.086.6
3798.698.5
40104.0104.0
50122.0121.3
75167.0167.5
100212.0211.6

Learning task

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.

Other Supervised Datasets

Examples

  • Regression dataset: house size → price.
  • Classification dataset: student features → pass/fail label.

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.

Learning Algorithm Overview

We choose a simple model:

ŷ = wC + b

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

Interactive Linear Regression: Change w and b

Blue points = training data, red line = your current model line.

Try it yourself

ŷ = 1.80C + 32.00
MSE
0.22
Prediction at 25°C
77.00°F

As you move the sliders, watch the line rotate and shift. Better values of w and b reduce the prediction error.

Colab Code: Train the Model


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])
  

Interactive Demo: Formula vs Learned Model

Move the slider and compare both predictions.

Input

25°C

Predictions

Formula uses exact domain knowledge. ML estimates the relationship from examples.

Mini Activity: Think Before Answering

If a model is trained only on temperatures between 0°C and 40°C, should we fully trust its prediction for 300°C?

Why This Example Matters

Known rule

For Celsius → Fahrenheit, the exact mathematical rule is known, so traditional programming is enough and often better.

Unknown rule

For medical diagnosis, fraud detection or image recognition, the rule is difficult to write manually. ML becomes useful because it can learn from examples.

Takeaways

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.

Questions?

Next class: Linear Regression and Model Evaluation