First time studying this topic?

Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.

Topic 1.5

Introduction to Machine Learning

Grasp the core engine of modern AI: learning patterns from data without being explicitly programmed.

Learning Objectives

  • ✓Articulate Arthur Samuel’s foundational definition of Machine Learning
  • ✓Understand features, labels, training sets, and test sets
  • ✓Examine the iterative training feedback loop
  • ✓Distinguish between model parameters and hyperparameters

📖Let's Begin with a Story

In 1959, IBM computer scientist Arthur Samuel created a computer program that played checkers. Samuel was not an extraordinary checkers champion—in fact, many amateur players could beat him. Instead of trying to program grandmaster strategies by hand, Samuel wrote a program that played thousands of games against itself, keeping track of board positions that correlated with eventual victory and discarding positions that led to defeat. Within months, the program began consistently beating Samuel himself, and eventually defeated the Connecticut state checkers champion. Samuel coined the term "Machine Learning," describing it as the field of study that gives computers the ability to learn without being explicitly programmed.

Why Should You Learn Introduction to Machine Learning?

🎯 Practical & Engineering Stakes

Why Machine Learning is the defining technology of our era:

1. Scalability: While human knowledge transfer takes decades of schooling, an ML model can digest 10 million textbooks overnight. 2. High-dimensional pattern recognition: Humans can visualize 3 dimensions; ML easily finds mathematical relationships across 10,000 dimensions. 3. Continuous adaptability: As market trends or customer habits shift, ML models retrain and adjust dynamically.

What Is It?

Simple Explanation

Machine Learning is like teaching a child to recognize fruits. You don't give them a math formula for an apple; you show them 100 apples of different sizes and colors. Eventually, their brain learns the visual pattern. Machine learning does the exact same thing with computers and numbers.

Technical Explanation

Machine Learning is a subset of AI centered on statistical optimization algorithms that improve performance metric PP at task TT through experience EE (Tom Mitchell, 1997). The system adjusts internal weight tensors W\mathbf{W} via gradient estimation over loss manifolds.

📚 Key Terms

Features (XX)

Simple: The clues or measurements given to the computer (e.g., house size, bedrooms, location).
Technical: Individual measurable properties or attributes of an observed phenomenon represented as a vector x∈Rd\mathbf{x} \in \mathbb{R}^d.

Labels (yy)

Simple: The true answer the computer is trying to predict (e.g., house sale price).
Technical: The ground-truth dependent variable or target value assigned to an instance in supervised learning.

Model Parameters

Simple: The internal dials the computer adjusts during learning.
Technical: Internal variables (e.g., weights and biases) whose values are estimated directly from data during the training process.

📐 Mathematical Foundation

LaTeX KaTeX
y=f(X;W,b)=WTX+by = f(X; \mathbf{W}, b) = \mathbf{W}^T X + b

What does it mean?

The fundamental linear model: multiplying inputs X by weights W and adding bias b to predict output y.

Understanding the Symbols

Symbol / TermMeaningBeginner Interpretation
XXInput featuresMeasurements fed into the system
W\mathbf{W}Weight vectorImportance weight assigned to each feature
bbBias scalarBaseline offset when all features are zero

📊 Numerical Example

Predicting car price based on mileage (in thousands): base price $25,000 with -$150 per thousand miles.

y=(−0.15×40)+25=−6+25=19y = (-0.15 \times 40) + 25 = -6 + 25 = 19

Result: Estimated value: $19,000 for a car with 40,000 miles

⚙️ How Does It Work?

1

Data Preparation

Raw data is cleaned, normalized, and partitioned into training, validation, and test splits.

2

Model Architecture Selection

Select an algorithm (Linear Model, Decision Tree, Support Vector Machine, Neural Network).

3

Training (Weight Optimization)

Model makes predictions, evaluates errors against ground truth, and updates weights via gradient descent.

4

Evaluation & Inference

Model accuracy is verified on unseen test data before real-world production deployment.

🌍 Where Is It Used?

Real Estate Price Valuation (Zillow Zestimate)

Problem: Assessing property market value across diverse neighborhoods without manual home appraisals.

Solution: Ensemble models analyze square footage, school ratings, and recent neighborhood sales to estimate valuation in real-time.

Customer Churn Prediction

Problem: Telecom companies losing subscribers to competitors without warning.

Solution: ML classifies users showing declining usage and proactively triggers personalized retention discounts.

🎯 Try It Yourself

In a medical dataset used to predict diabetes risk, which of the following is the LABEL?

Interactive activity component

🐍 Python Hands-On: Lesson 2: Classical Machine Learning — House Price Prediction with Linear Regression

Train a linear regression model on house sizes and prices, predict prices for unseen square footage, and plot the regression line using matplotlib.

Open Colab

1Install Required Packages

For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:

Terminal / Notebook Install Commandbash
!pip install scikit-learn numpy matplotlib
Packages:
scikit-learnnumpymatplotlib

2Import Libraries

Import Statementspython
1import numpy as np
2import matplotlib.pyplot as plt
3from sklearn.linear_model import LinearRegression

import numpy as np → Array manipulation and matrix reshaping

import matplotlib.pyplot as plt → Plot data points and regression line

from sklearn.linear_model import LinearRegression → Ordinary Least Squares linear regression model

3Demonstration Code & Logic

Python Execution Codepython
1# Data: House sizes (sq ft) and corresponding prices
2X = np.array([500, 700, 900, 1100, 1300]).reshape(-1, 1) # Feature (sq ft)
3y = np.array([150000, 180000, 210000, 250000, 280000]) # Target (price in $)
4
5# Create Linear Regression model
6model = LinearRegression()
7
8# Train the model on the data
9model.fit(X, y)
10
11# Predict price for a house with 1000 sq ft
12predicted_price = model.predict([[1000]])
13print(f"Predicted Price for 1000 sq ft house: ${predicted_price[0]:,.2f}")
14
15# Plot Data and Regression Line
16plt.scatter(X, y, color='blue', label="Actual Prices")
17plt.plot(X, model.predict(X), color='red', label="Regression Line")
18plt.xlabel("House Size (sq ft)")
19plt.ylabel("House Price ($)")
20plt.title("Linear Regression - House Price Prediction (Lesson 2)")
21plt.legend()
22plt.show()
Step-by-Step Code Breakdown:

# Data: House sizes (sq ft) and corresponding prices

Define training dataset

X = np.array([500, 700, 900, 1100, 1300]).reshape(-1, 1) # Feature (sq ft)

Reshape feature into 2D array

y = np.array([150000, 180000, 210000, 250000, 280000]) # Target (price in $)

Continuous target values

# Create Linear Regression model

Instantiate linear regressor

model = LinearRegression()

Initialize estimator

# Train the model on the data

Fit model parameters (slope and intercept)

model.fit(X, y)

Execute gradient/normal equation fitting

# Predict price for a house with 1000 sq ft

Run inference on unseen feature

predicted_price = model.predict([[1000]])

Evaluate model at X=1000

print(f"Predicted Price for 1000 sq ft house: ${predicted_price[0]:,.2f}")

Print estimated price

# Plot Data and Regression Line

Visualization with matplotlib

plt.scatter(X, y, color='blue', label="Actual Prices")

Scatter plot of ground-truth points

plt.plot(X, model.predict(X), color='red', label="Regression Line")

Fitted linear boundary

plt.xlabel("House Size (sq ft)")

Set X-axis label

plt.ylabel("House Price ($)")

Set Y-axis label

plt.title("Linear Regression - House Price Prediction (Lesson 2)")

Set plot title

plt.legend()

Display legend

plt.show()

Render plot figure

📋 Complete Script (All-in-One)

Click "Copy for Colab", open Google Colab, paste into a single cell, and run.

Google Colab Notebook Scriptpython
1# =========================================================
2# Lesson 2: Classical Machine Learning — House Price Prediction with Linear Regression
3# Prepared for Google Colab (Run with Shift + Enter)
4# =========================================================
5
6# Step 1: Install required packages
7!pip install scikit-learn numpy matplotlib
8
9# Step 2: Import libraries
10import numpy as np
11import matplotlib.pyplot as plt
12from sklearn.linear_model import LinearRegression
13
14# Step 3: Run Demonstration
15# Data: House sizes (sq ft) and corresponding prices
16X = np.array([500, 700, 900, 1100, 1300]).reshape(-1, 1) # Feature (sq ft)
17y = np.array([150000, 180000, 210000, 250000, 280000]) # Target (price in $)
18
19# Create Linear Regression model
20model = LinearRegression()
21
22# Train the model on the data
23model.fit(X, y)
24
25# Predict price for a house with 1000 sq ft
26predicted_price = model.predict([[1000]])
27print(f"Predicted Price for 1000 sq ft house: ${predicted_price[0]:,.2f}")
28
29# Plot Data and Regression Line
30plt.scatter(X, y, color='blue', label="Actual Prices")
31plt.plot(X, model.predict(X), color='red', label="Regression Line")
32plt.xlabel("House Size (sq ft)")
33plt.ylabel("House Price ($)")
34plt.title("Linear Regression - House Price Prediction (Lesson 2)")
35plt.legend()
36plt.show()
⚡ How to Run in Google Colab (3 Quick Steps)
  1. Click "Copy for Google Colab" above.
  2. Click Open New Google Colab Notebook (opens in a new tab).
  3. Click on the first empty code cell, press Ctrl + V (or Cmd + V) to paste, then press Shift + Enter to execute!

🔄 Algorithmic Execution Flow

1
Dataset Formatting

Input feature square footage is converted to a 2D column vector and paired with price targets.

→
2
Model Training

Scikit-Learn computes the optimal slope and intercept minimizing Mean Squared Error.

→
3
Inference

Model predicts the price for a 1,000 sq ft house ($230,000.00).

→
4
Visual Regression Line

Matplotlib plots the actual data points alongside the learned continuous regression line.

📥 Input / Initial State
House Sizes: [500, 700, 900, 1100, 1300] sq ft, Target Query: 1000 sq ft
📤 Expected Output
Predicted Price for 1000 sq ft house: $230,000.00
💡 What Does This Demonstration Show?

Demonstrates supervised learning regression: the model discovers the underlying linear relationship Price = m * Area + c and generalizes to unseen house sizes.

Course Learning Resource • Slide DeckLesson 211 Slides

Lesson 2: Classical Machine Learning as the Starting Point

Data, prediction, and the bridge to modern AI — Presentation by Dr. Syed Muzamil Basha.

Author: Dr. Syed Muzamil Basha• FDP Approved Curriculum
Open in New Tab

📝 Learning Check

Test your understanding with these questions. Remember, this is for learning, not examination!

Question 1: According to Tom Mitchell’s classic definition, a computer program is said to learn from experience E with respect to task T and performance measure P if:

Question 2: In the linear model y = W^T X + b for predicting car prices, what does the weight W for the mileage feature represent?

Question 3: A model has excellent accuracy on its training set but performs poorly on new unseen emails. What ML issue does this most likely describe?

Question 4: What is the key difference between model parameters and hyperparameters?

Question 5: Arthur Samuel's checkers program surpassed its creator without explicitly programmed strategies. Which aspect of ML does this best illustrate?

Question 6: In the ML training pipeline, which step must come FIRST?