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
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.
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.
Give the syllabus meaning of machine learning.
A video site suggests new videos based on what you watched. How does this show machine learning?
Give one difference between an expert system and a machine learning program.
Why might a learning program give poor results even after a lot of training?
A filter makes 45 mistakes on 300 emails. After more training it makes 18. 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.