Skip to main content
Chapter 6 of 8
~20 min read
Last reviewed July 17, 2026

Introduction to AI and Machine Learning

Supervised versus unsupervised learning, the confusion matrix, calculating accuracy, and how ML is applied in the real world.

Written and reviewed by the IK Learning team

  • Supervised Learning
  • Unsupervised Learning
  • Confusion Matrix
  • Accuracy
  • AI vs ML
  • Linear Regression

This chapter introduces Artificial Intelligence and Machine Learning, explaining the difference between supervised and unsupervised learning, how to evaluate a model using a confusion matrix and accuracy, and real-world applications of AI and ML.

Chapter Introduction

What this chapter is about, and why it matters

Class 9 introduced what AI and machine learning are. This chapter is about how machine learning actually works and — more importantly — how you tell whether it is working well.

The central division is between supervised learning, where the training data comes with correct answers attached, and unsupervised learning, where it does not. Nearly every question in this chapter depends on placing a scenario correctly on that line.

The confusion matrix is where students lose the most marks, almost always by mixing up false positives and false negatives. Learn to read the words literally — "false positive" means the system said positive and was false — and it becomes mechanical.

What You Will Learn

The skills this chapter is assessed on

  • Distinguish supervised from unsupervised learning and classify examples of each.
  • Explain what training data and labels are, and why data quality limits model quality.
  • Read a confusion matrix and identify true/false positives and negatives.
  • Calculate accuracy from a confusion matrix and explain when accuracy is misleading.
  • Describe what linear regression does and give an appropriate use for it.

Key Concepts Explained

8 core ideas — each with its definition and a separate worked example

Machine learning

Definition

Machine learning is a branch of artificial intelligence in which a system learns patterns from data and uses them to make predictions or decisions, without being explicitly programmed with the rules for the task.

Example

A system that predicts a student's final grade from their attendance and test scores is not given a formula. It is shown hundreds of past students' records and works out the relationship itself.

Supervised learning

Definition

Supervised learning is a machine learning approach in which the model is trained on data where each example is already labelled with the correct answer, so the model learns to map inputs to known outputs.

Example

Training an email filter on 50,000 emails each already marked "spam" or "not spam". The label is the supervision — the model checks its guess against the known answer and adjusts.

Detailed Explanation

The word "supervised" refers to the labels, not to a person watching. If the training data contains the right answers, it is supervised, and the practical cost is that someone had to produce those labels first.

Unsupervised learning

Definition

Unsupervised learning is a machine learning approach in which the model is trained on data with no labels, and must discover structure, groupings or patterns in the data by itself.

Example

Giving a shop's system a year of purchase records with no categories attached. It groups customers into clusters with similar buying habits. Nobody defined the groups in advance — the model found them.

Detailed Explanation

The output of unsupervised learning needs human interpretation. The system can report that three distinct groups exist; deciding that group two are "weekly bulk shoppers" is a judgement a person makes afterwards.

Training data and labels

Definition

Training data is the set of examples used to teach a machine learning model. A label is the known correct output attached to a training example in supervised learning.

Example

For a model recognising handwritten digits, the training data is thousands of digit images, and each image's label is the number a human confirmed it shows.

Detailed Explanation

Data is normally split so that some examples are held back for testing. Evaluating a model on the same data it learned from is like marking a test using the answer sheet the student memorised — it measures recall, not understanding.

Confusion matrix

Definition

A confusion matrix is a table used to evaluate a classification model, showing the counts of true positives, true negatives, false positives and false negatives produced when its predictions are compared with the actual correct answers.

Example

A spam filter tested on 100 emails:

                  Actually     Actually
                  Spam         Not Spam
Predicted Spam      40 (TP)       5 (FP)
Predicted Not Spam   3 (FN)      52 (TN)

Detailed Explanation

Read each term literally, in two words. "False positive" = predicted positive, and that was false → a genuine email sent to the spam folder. "False negative" = predicted negative, and that was false → spam that reached the inbox. Once you read them this way they stop being interchangeable.

Accuracy

Definition

Accuracy is the proportion of all predictions that were correct, calculated as the number of true positives plus true negatives, divided by the total number of predictions.

Example

From the matrix above: (40 + 52) ÷ 100 = 0.92, or 92% accuracy. Ninety-two of the hundred emails were classified correctly.

Detailed Explanation

Accuracy is misleading when one outcome is rare. If only 1 email in 100 were spam, a model that simply labelled everything "not spam" would be 99% accurate and completely useless. Always ask what the split of the data was before trusting an accuracy figure.

Why false positives and false negatives differ in cost

Definition

The two error types have different real-world consequences, so the acceptable balance between them depends on the application rather than on mathematics alone.

Example

For a medical screening test, a false negative tells a sick patient they are healthy — potentially fatal. A false positive causes worry and a second test. Here the system should be tuned to minimise false negatives, even at the cost of more false positives.

Detailed Explanation

For a spam filter the priority reverses: losing an important email in the spam folder (false positive) is worse than seeing one spam message in the inbox. This is why "which error matters more?" is an application question, and why exam answers should name the context.

Linear regression

Definition

Linear regression is a supervised learning technique that models the relationship between variables by fitting a straight line through the data, allowing a continuous numeric value to be predicted from an input.

Example

Plotting hours studied against marks scored for 200 students and fitting a line through the points. The line can then estimate the marks for a student who studied a number of hours not present in the original data.

Detailed Explanation

Regression predicts a number (marks, price, temperature); classification predicts a category (spam or not spam). Questions asking which technique fits a problem are really asking whether the answer is a quantity or a label.

Step-by-Step Worked Examples

How to lay the answer out so method marks are earned

Calculating accuracy from a confusion matrix

Question: A model tested on 200 samples produced 70 true positives, 100 true negatives, 20 false positives and 10 false negatives. Calculate its accuracy and comment on the result.

  1. Identify the correct predictions: true positives + true negatives = 70 + 100 = 170.
  2. Identify the total number of predictions: 70 + 100 + 20 + 10 = 200.
  3. Apply the formula: accuracy = correct ÷ total = 170 ÷ 200.
  4. Convert to a percentage: 0.85 × 100.
  5. Check the balance of the data before judging: 80 samples were actually positive and 120 actually negative, so the classes are reasonably balanced.

Answer

Accuracy = 85%. Because the two classes are reasonably balanced, 85% is a meaningful figure here. Had 195 of the 200 samples been negative, the same accuracy would have been close to worthless.

Where This Is Used in Real Life

The same ideas, outside the syllabus

Recommendation systems

Video and shopping platforms use both approaches: unsupervised clustering groups users with similar tastes, and supervised models predict whether a specific user will click a specific item. The recommendation you see is the output of both working together.

Medical screening

Screening tools are deliberately tuned towards more false positives to reduce false negatives, because a follow-up test is far cheaper than a missed diagnosis. This is the confusion matrix influencing a life-and-death design decision.

Predicting exam performance

A school could use linear regression on attendance and past scores to identify students likely to struggle, so support arrives before the exam rather than after it. The same prediction also raises fairness questions worth discussing.

Common Mistakes to Avoid

Errors that cost marks in this chapter, and the correction for each

Mistake

Swapping false positives and false negatives.

Correct Approach

Read the phrase literally: the second word is what the model predicted, the first says whether that prediction was right. False positive = predicted positive, was wrong.

Mistake

Defining supervised learning as "learning with a teacher watching".

Correct Approach

The supervision is the labelled data — correct answers supplied with the training examples. No person watches the training.

Mistake

Treating a high accuracy figure as proof that a model is good.

Correct Approach

On imbalanced data, accuracy is misleading. A model predicting the majority class every time can score 99% and be useless.

Mistake

Testing a model on the same data used to train it.

Correct Approach

Data must be split into training and testing sets, or the evaluation measures memorisation rather than genuine performance.

Mistake

Confusing regression with classification.

Correct Approach

Regression predicts a continuous number. Classification predicts a category. Ask what kind of answer the problem needs.

Mistake

Calculating accuracy using only the true positives.

Correct Approach

The formula is (TP + TN) ÷ total. Correct negatives are correct predictions too, and omitting them halves your answer.

Exam Preparation Tips

Technique specific to this chapter

  • Draw the confusion matrix as a labelled 2×2 grid before answering any question about it. Labelling the rows "predicted" and the columns "actual" prevents almost every error.
  • Show the accuracy calculation as a fraction before converting to a percentage — method marks are available even if the arithmetic slips.
  • When classifying a scenario as supervised or unsupervised, state the reason: "supervised, because each training example already carries the correct label".
  • For questions about which error type matters more, name the application. The answer genuinely depends on it, and examiners want to see that recognised.
  • Keep one clear example each of classification and regression ready. Named examples earn marks that general descriptions do not.

Quick Revision Summary

The whole chapter in one screen — read this the night before

  • Supervised = training data has labels (correct answers).
  • Unsupervised = no labels; the model finds structure such as clusters.
  • Labels must be produced by humans, which is what makes supervised data expensive.
  • Split data into training and testing sets; never evaluate on training data.
  • Confusion matrix: TP, TN, FP, FN.
  • False positive = predicted positive, actually negative.
  • False negative = predicted negative, actually positive.
  • Accuracy = (TP + TN) ÷ total predictions.
  • Accuracy misleads on imbalanced data.
  • Regression predicts a number; classification predicts a category.

Glossary of Terms

Words used in this chapter, defined plainly

Label
The known correct output attached to a training example.
Feature
An input variable the model uses to make its prediction.
Model
The trained result that makes predictions on new data.
Clustering
Grouping similar items together without predefined categories.
Overfitting
When a model memorises its training data and performs poorly on new data.
Prediction
The output a model produces for an input it has not seen before.
Imbalanced data
A data set where one outcome is far more common than the other.

Practice Questions

Now test yourself on the concepts above. Collapse the answers to make it a real practice run.

Multiple Choice Questions with Explanations

9 MCQs — pick an option to check yourself, then read why the answer is right

1How is Artificial Intelligence (AI) best described?

Correct answer: BMachines performing tasks like humans

Artificial Intelligence enables machines to perform tasks that normally require human intelligence, such as reasoning and learning.

2Which of these counts as an example of AI?

Correct answer: AA chatbot replying to your questions

A chatbot that understands and answers questions uses AI, unlike simple everyday devices that follow fixed actions.

3How is Machine Learning (ML) best described?

Correct answer: BTeaching machines to learn from data like humans

Machine Learning is about teaching machines to learn patterns from data rather than being explicitly programmed for every task.

4Which app uses ML to recommend videos?

Correct answer: CYouTube

YouTube uses machine learning to study viewing habits and recommend videos a user is likely to enjoy.

5In supervised learning, the data used is:

Correct answer: CLabeled with correct answers

Supervised learning trains on data that is labeled with the correct answers so the model can learn to predict them.

6Which of these is an example of unsupervised learning?

Correct answer: DGrouping students by interest without labels

Unsupervised learning finds hidden patterns in unlabeled data, such as grouping students by interest without any given labels.

7Google Assistant is an example of:

Correct answer: CA smart assistant using AI

Google Assistant is an AI-powered smart assistant that understands voice commands and responds intelligently.

8AI is chiefly applied to:

Correct answer: DSmart decision making and automation

AI is mainly applied to smart decision-making and the automation of tasks that would otherwise need human effort.

9A chatbot on JazzCash is an example of:

Correct answer: CAI in business

A chatbot on JazzCash is an example of AI in business, using automation to assist and respond to customers.

Short Questions with Answers

8 short-answer questions

Artificial Intelligence (AI) is the broader concept of machines performing tasks like humans, whereas Machine Learning (ML) is a subset of AI in which machines learn from data to make predictions or decisions. Example: A self-driving car as a whole is AI, while the part that learns to recognise traffic signs from thousands of images is ML.
AI in Pakistan means the use of artificial intelligence in local services and applications so that customer queries are answered and tasks are carried out automatically. Example: The chatbots found on JazzCash and bank websites that answer customer questions without a human agent.
Supervised learning is a type of machine learning in which the machine is trained on labeled data. It generates predictions, compares them against the correct answers, and uses this feedback to adjust and become more accurate over time. Example: Training a model on emails already marked as "spam" or "not spam" so that it can classify new emails correctly.
A confusion matrix is a table that shows the correct and incorrect predictions of a classification model using four values: TP (True Positive), TN (True Negative), FP (False Positive), and FN (False Negative). Example: If a spam filter tests 100 emails and correctly identifies 40 spam (TP) and 50 not-spam (TN), but wrongly marks 6 (FP) and misses 4 (FN), these figures are placed in the confusion matrix.
Businesses use AI to automate tasks and improve their services through customer analysis, chatbots, and recommendation systems, which saves both time and cost. Example: An online store uses AI to suggest products to a customer based on their past purchases.
A smart assistant is an AI program that understands voice commands and performs tasks for the user, while a recommendation system is an AI system that suggests content based on a user past activity. Example: Smart assistant — Google Assistant; Recommendation system — YouTube video suggestions.
Unsupervised learning relies on unlabeled, raw, and unstructured data that has no correct answers attached, and it needs large and varied datasets such as collections of images. Example: Giving a model thousands of unlabeled customer records so that it groups similar customers together on its own.
Linear Regression is a supervised machine learning technique that finds a straight-line relationship between an input variable and an output variable, and then uses that line to predict a numeric value. Example: Predicting a student marks from the number of study hours, where more study hours give a higher predicted result.

Long Questions with Detailed Answers

3 in-depth answers

Machine learning can broadly be split into two main types: Supervised Learning and Unsupervised Learning. - Supervised Learning In supervised learning, the machine is given data along with correct answers (labels). It learns by comparing its own guesses against the correct answers, and its accuracy improves over time. Definition: Supervised learning is when the machine is trained using labeled data, where both the instance and the correct output are provided. Example 1: Suppose you are training a machine to tell whether a fruit is an apple or a mango. You show it many apples and mangoes, each labeled as such: 1. "This is an Apple" 2. "This is a Mango" The computer learns and can later predict with high accuracy when shown new pictures of apples and mangoes. Example 2: A system can be trained on students' marks and attendance to predict who might fail. - Unsupervised Learning In unsupervised learning, the machine is given only data with no labels attached. It must find patterns or group similar things on its own. Definition: Unsupervised learning is when the machine discovers patterns or groups within unlabeled data without being told what the correct answer is. This helps a store market its products more effectively, even without knowing the exact customer types. Example: A school wants to divide students into study groups. The system reviews their interests and subjects and forms groups purely based on similarities, without knowing which grouping is "best". - Difference between Supervised and Unsupervised Learning The difference between the two types of learning is shown in the following table. Feature | Supervised Learning | Unsupervised Learning Labeled Data? | Yes (machine is told the correct answers) | No (machine finds patterns on its own) Main Task | Predict or classify | Group or cluster similar data Example | Predict student results using marks and | Group customers based on shopping behavior | study hours | Uses in School | Identify students who need help | Make automatic student groups for projects
- Evaluating Model Performance Once an ML model is trained (for example, to predict who will buy a product or whether a message is spam), its performance needs to be measured. This helps determine whether the model is accurate and reliable. - Confusion Matrix A confusion matrix is a table used to evaluate a classification model by showing how many predictions were correct or incorrect. The table below shows a simple confusion matrix for predicting whether a student will pass or fail (a classification problem). | Predicted: Pass | Predicted: Fail Actual: Pass | True Positive (TP) | False Negative (FN) Actual: Fail | False Positive (FP)| True Negative (TN) 1. True Positive (TP): Model predicted pass, and the student actually passed. 2. True Negative (TN): Model predicted fail, and the student actually failed. 3. False Positive (FP): Model predicted pass, but the student actually failed. 4. False Negative (FN): Model predicted fail, but the student actually passed. The confusion matrix helps show whether a model is making classification or prediction mistakes, and it feeds into calculating the accuracy (an important measure) of the model. - Accuracy Accuracy (A) tells us how many predictions were correct out of all predictions made. It is calculated as follows: Accuracy = (TP + TN) / (TP + TN + FP + FN) Suppose we have data for 15 students. In reality, 8 students passed while 7 failed. The model produced the following results: 1. TP = Correctly predicted pass = 7 2. TN = Correctly predicted fail = 5 3. FP = Wrongly predicted pass = 2 4. FN = Wrongly predicted fail = 1 Using the formula above with these results, accuracy is calculated as: A = (7 + 5) / (7 + 5 + 2 + 1) = 12 / 15 = 0.80 or 80%
Given Data 1. Total students = 20 2. TP = 8 (predicted pass, actually pass) 3. TN = 6 (predicted fail, actually fail) 4. FP = 4 (predicted pass, actually fail) 5. FN = 2 (predicted fail, actually pass) (a) Confusion Matrix (a) | Predicted: Pass | Predicted: Fail Actual: Pass | TP = 8 | FN = 2 Actual: Fail | FP = 4 | TN = 6 Confusion matrix filled in. (b) Accuracy Calculation (b) Accuracy formula: Accuracy = (TP + TN) / (TP + TN + FP + FN) Plugging in the numbers: Accuracy = (8 + 6) / (8 + 6 + 4 + 2) = 14 / 20 Accuracy = 0.7 or 70% 1. Confusion Matrix: | Predicted: Pass | Predicted: Fail Actual: Pass | 8 | 2 Actual: Fail | 4 | 6 1. Accuracy: 70%

Important Questions for Revision

4 high-priority questions

AI (Artificial Intelligence): The broader concept of machines carrying out tasks that normally require human intelligence — such as understanding voice, recognizing images, or making decisions. Example: A traffic control system in Lahore, chatbots on bank websites. ML (Machine Learning): A subset of AI where machines learn from data on their own to make predictions or decisions without being explicitly programmed each time. Example: YouTube recommending videos based on watch history, weather apps predicting tomorrow's temperature. Key Difference: AI is the goal (smart machines); ML is one method used to achieve it (learning from data).
In supervised learning, the machine is trained using labeled data — data where both the input and the correct output (label) are supplied. The machine learns by: - Looking at examples with correct answers - Making its own predictions - Comparing its predictions against the correct answers - Adjusting to become more accurate over time Example: Training a model to identify fruits as Apple or Mango by showing many labeled images of each. Later, when shown a new image, it predicts correctly. Real-world use: Predicting whether a student will pass or fail based on their marks and attendance.
A confusion matrix is a simple table that shows how many predictions made by a classification model were correct or incorrect. It has four values: 1. True Positive (TP): Model predicted Pass — student actually passed ✓ 2. True Negative (TN): Model predicted Fail — student actually failed ✓ 3. False Positive (FP): Model predicted Pass — but the student actually failed ✗ 4. False Negative (FN): Model predicted Fail — but the student actually passed ✗ It helps evaluate whether a model is making mistakes and is used to calculate Accuracy = (TP+TN)/(TP+TN+FP+FN).
Supervised Learning: The machine is trained with labeled data (correct answers are provided). Main task: Predict or classify Example: A model trained on student marks and attendance to predict who might fail. The training data already has labels (pass/fail) attached. Unsupervised Learning: The machine is given only data with no labels. It finds patterns or groups by itself. Main task: Group or cluster similar data Example: A school system that sorts students into study groups by checking their interests — without being told what the "correct" groups should be. Comparison: Supervised → uses labeled data → predicts outcomes Unsupervised → uses unlabeled data → discovers hidden patterns

Frequently Asked Questions

6 quick answers to common questions about this chapter

AI is the broad goal of building machines that can perform tasks requiring human-like intelligence. Machine Learning (ML) is one specific approach used to achieve that goal, where a machine learns patterns directly from data instead of following rules a programmer wrote by hand. ML is a subset, or method, within the wider field of AI.
Neither is "better" — they solve different problems. Supervised learning is used when you already have labeled correct answers and want the machine to predict outcomes, like pass/fail. Unsupervised learning is used when there are no labels and you want the machine to discover hidden groupings on its own, like customer segments.
If a spam filter checks 100 emails, a confusion matrix would show how many spam emails it correctly flagged, how many normal emails it correctly left alone, and how many it got wrong in either direction — giving a full picture of the filter's actual performance, not just a single number.
A model can score a high accuracy percentage while still making serious mistakes on important cases — for example, missing rare but critical fraud cases. Looking at the full confusion matrix (not just accuracy) shows exactly what kind of errors a model is making.
Yes. Supervised and unsupervised learning, the confusion matrix, calculating accuracy, and real-world applications of AI and ML are all examinable topics covered through MCQs and short/long answer questions.
Accuracy is calculated as (True Positives + True Negatives) divided by the total number of predictions made (TP + TN + FP + FN). For example, if a model correctly predicts 12 out of 15 outcomes, its accuracy is 12 ÷ 15 = 0.80, or 80%.

Chapter Test

9 questions with the answers hidden — check what you actually remember

You have just read the explanations above. This checks whether they stuck. The answers stay hidden until you finish, so it is closer to exam conditions than scrolling through the notes again.

  • 9 questions, one at a time — no time limit.
  • You can move back and change an answer before submitting.
  • Afterwards you get your score, every explanation, and what to re-read.

Your score is saved in this browser only. No account, nothing sent anywhere.

Related Topics in the Other Class