HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Artificial Intelligence: Expert Systems and Machine Learning
  1. 1What artificial intelligence is
  2. 2Expert systems
  3. 3Machine learning
  1. Computer Science
  2. /Artificial Intelligence: Expert Systems and Machine Learning
  3. /Machine learning

Course 6.3·Lesson 3 of 3

Machine learning

Machine learning is when a program has the ability to automatically adapt its own processes and/or data. This lesson shows a filter that learns which emails are unwanted. It compares learning with an expert system. Then you find the best rule from examples, as a learning program does.

about 25 min1 simulation1 practice question
Lesson 3 of 3Show all lessonsHide
Artificial Intelligence: Expert Systems and Machine Learning
  1. 1What artificial intelligence is
  2. 2Expert systems
  3. 3Machine learning

Try the code and the simulations beside the lesson.

A filter that gets better

When you first set up an email account, some unwanted messages get through. Each time you mark one as unwanted, the filter changes. A week later, far fewer get through. Nobody rewrote the filter's program by hand. The program changed itself, using the examples you gave it. This is machine learning.

What machine learning is

Machine learning is when a program has the ability to automatically adapt its own processes and/or data.

  • Its own data. The filter keeps a store of words that appear in unwanted mail. Each marked email adds to that store. The data changes, so the filter's decisions change.
  • Its own processes. A program can also change the way it decides, for example the dividing line between "wanted" and "unwanted", or the weight it gives to each clue.

The data a program learns from is often called training data. The more good examples it sees, the better it usually becomes. Machine learning is how a program gets the third characteristic of AI: the ability to learn and adapt.

Examples

  • A filter for unwanted email that improves as people mark messages.
  • A shopping or video site that suggests items based on what you chose before, and changes its suggestions as you choose more.
  • A program that recognises handwriting or speech, trained on many examples.
  • A game program that improves by playing many games and keeping the moves that won.

Expert systems and machine learning compared

  • Where the rules come from. In an expert system, people write the rules from the knowledge of experts. In machine learning, the program finds and changes its own rules from data.
  • Change. A simple expert system stays the same until a person updates it. A learning program adapts by itself when new data arrives.
  • Explanation. An expert system can show the rules it used. A learning program's reasons can be harder to see.

Finding the best rule from examples

Two number lines of suspicious-word counts from 0 to 10. Wanted emails, drawn as blue circles, are at 1, 2, 3 and 5. Unwanted emails, drawn as red squares, are at 4, 6, 7 and 9. On the top line a dashed dividing line at 1.5 sorts 5 of the 8 correctly. On the bottom line, after learning, the dividing line at 5.5 sorts 7 of the 8 correctly.

The simulation shows eight emails. Each one has a count of suspicious words, and a label from the user: wanted or unwanted. The program must choose a dividing line. Try every line, count how many emails it sorts correctly, and keep the best: that is learning from data. Notice that no line gets all eight right. Real data is untidy, so a learning program aims for the best it can do, not perfection.

The learning step in pseudocode

The box marked pseudocode is Cambridge pseudocode. It is shown, not run. The Python box after it does a fuller version of the same job, and you can run it.

pseudocode
// Word[1:100] holds the words the filter knows.
// Count[1:100] holds how often each one was
// in a message marked as unwanted.
// InMessage[1:100] is TRUE for each word
// that is in the message just marked.
FOR Index ← 1 TO 100
    IF InMessage[Index] = TRUE
      THEN
        Count[Index] ← Count[Index] + 1
    ENDIF
NEXT Index

The array Count is the program's own data. Each time the user marks a message, this loop changes it, so the filter's later decisions change too.

Try it in Python

The program starts with an empty store of words. Three messages are marked as unwanted, so the store fills up. Then it scores three new messages.

Read it first. Then run it. Why does the harmless message about lunch get a score of 1?

1. Add the message "lunch money for free" to marked. Predict the new score of the lunch message, then run it.

2. Which line is the program adapting its own data?

Practise with new numbers

Common mistakes

  • Machine learning means a person reprograms it. The program adapts automatically.
  • Every AI system uses machine learning. An expert system with fixed rules is AI but does not learn.
  • More data always means perfect results. Learning reduces mistakes, but poor or one-sided data can teach the program the wrong thing.
  • Learning only changes data. It can change the program's processes as well.

Remember these

  • Machine learning: a program has the ability to automatically adapt its own processes and/or data.
  • It learns from examples, often called training data.
  • Expert system: rules written from human experts. Machine learning: the program adapts its own rules and data.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Give the syllabus meaning of machine learning.
  1. A video site suggests new videos based on what you watched. How does this show machine learning?
  1. Give one difference between an expert system and a machine learning program.
  1. Why might a learning program give poor results even after a lot of training?
  1. A filter makes 454545 mistakes on 300300300 emails. After more training it makes 181818. By how many percentage points did its accuracy rise?

Enroll free in Artificial Intelligence: Expert Systems and Machine Learning

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (4)

An email service has a filter that moves unwanted messages into a separate folder…Medium · High School (9–10) · by StemPy Lab
A learning filter is given eight emails that users have labelled…Medium · High School (9–10) · by StemPy Lab
A bank wants software to decide which card payments might be fraud…Hard · High School (9–10) · by StemPy Lab
That was the last lessonBack to the course: take the test
← Artificial Intelligence: Expert Systems and Machine Learning
← Expert systemsNext →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

A filter calls an email unwanted when its score is greater than its dividing line T…Hard · High School (9–10) · by StemPy Lab

Python Labs (1)

A program that learns its dividing linePython Lab · by StemPy Lab

Question Sets (1)

Artificial Intelligence: Test Yourself10 questions · by StemPy Lab

Notes (1)

Artificial Intelligence: Quick RevisionNote · by StemPy Lab