Machine learning adapting its own data

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Machine learning adapting its own data

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A spam filter is told by a user that an email is spam. What does a machine learning spam filter do with this information?
A It ignores the email and keeps its data unchanged
B It adds the email's features to its stored data
2. Which statement describes machine learning adapting its own data?
A The program updates its stored values using new cases
B A programmer must rewrite the stored values by hand each time
3. A spam filter has stored that the word 'prize' appears in 60% of spam emails. After more users mark emails, it changes the value to 75%. What is this?
A Updating a stored value
B Deleting the filter's rules
4. Which is an example of a machine learning program removing stored information?
A The user deleting their own inbox folder
B Deleting an old example that no longer matches current spam
5. Why does a spam filter keep the data it has added or updated?
A It uses the data in later decisions about new emails
B It only stores the data and never uses it again

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1spam_examples.append(new_email) AThe program decides but never updates its stored data after the user marks the email. It must update word_score so the new case is used in later decisions.
2word_score["free"] = word_score["free"] + 1 BA fixed rule list is not being changed by the program itself. Machine learning should add the marked email to its own stored examples (the data), not leave it in rules that only a programmer edits.
3A spam filter removes an old example from its data when the user says it was marked wrongly Cspam_examples.remove(old_email)
4The updated stored data is used on later decisions, so the next email is judged using what was learned DThe program adds a newly marked email to its stored data so it can learn from it
5IF user_marks_spam THEN fixed_rules.append(email) ENDIF EThe program updates a stored value after seeing another spam email containing that word
6new_email = get_email() IF word_score["free"] > 5 THEN mark_as_spam (word_score is never changed) FIF word_score["free"] > 5 THEN mark_as_spam

Definitions

self-updating data

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF userMarksSpam = TRUE THEN spamData.___(emailWords) ENDIF
2.
IF word IN spamEmail THEN spamScore ← spamScore _ 1 ENDIF
3.
IF userSaysNotSpam THEN spamData.______(oldEmail) ENDIF
4.
score ← spamData.count(newEmail) IF _____ > 5 THEN OUTPUT "Move to spam"
5.
spamData.add(email) result ← ________.count(nextEmail)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A spam_words = ["win", "free"]
B new_word = "prize"
C if user_marked_spam:
D spam_words.remove(new_word)
Question 2
A def mark_spam(count):
B retrun count + 1
C spam_count = mark_spam(5)
D print(spam_count)
Question 3
A scores = {"free": 2, "win": 3}
B word = "free"
C scores[word] == scores[word] + 1
D print(scores)
Question 4
A trusted = []
B trusted.add("Sam")
C if "Sam" in trusted:
D print("Inbox")
Question 5
A spam_words = ["free", "win"]
B spam_words.remove(win)
C print(len(spam_words))

Answer Key

Machine learning adapting its own data
Section A: Quick Questions
Q1
B — It adds the email's features to its stored data
Q2
A — The program updates its stored values using new cases
Q3
A — Updating a stored value
Q4
B — Deleting an old example that no longer matches current spam
Q5
A — It uses the data in later decisions about new emails
Section B: Match the Pairs
Q1
spam_examples.append(new_email) → The program adds a newly marked email to its stored data so it can learn from it
Q2
word_score["free"] = word_score["free"] + 1 → The program updates a stored value after seeing another spam email containing that word
Q3
A spam filter removes an old example from its data when the user says it was marked wrongly → spam_examples.remove(old_email)
Q4
The updated stored data is used on later decisions, so the next email is judged using what was learned → IF word_score["free"] > 5 THEN mark_as_spam
Q5
IF user_marks_spam THEN fixed_rules.append(email) ENDIF → A fixed rule list is not being changed by the program itself. Machine learning should add the marked email to its own stored examples (the data), not leave it in rules that only a programmer edits.
Q6
new_email = get_email() IF word_score["free"] > 5 THEN mark_as_spam (word_score is never changed) → The program decides but never updates its stored data after the user marks the email. It must update word_score so the new case is used in later decisions.
Section C: Definitions
Q1
self-updating data — A machine learning program changes its own stored data by adding, updating or removing items as it meets new cases, e.g. spam marked by users, and uses that data in later decisions.
Section D: Fill in the Blanks
Q1
IF userMarksSpam = TRUE THEN spamData.add(emailWords) ENDIF
Q2
IF word IN spamEmail THEN spamScore ← spamScore + 1 ENDIF
Q3
IF userSaysNotSpam THEN spamData.remove(oldEmail) ENDIF
Q4
score ← spamData.count(newEmail) IF score > 5 THEN OUTPUT "Move to spam"
Q5
spamData.add(email) result ← spamData.count(nextEmail)
Section E: Spot the Error
Q1
D — When a user marks an email as spam, the program should add the new word to its stored data. remove() takes data away, so it should be spam_words.append(new_word).
Q2
B — The keyword is misspelt. It should be return, so the function gives back the updated spam count.
Q3
C — == compares two values and does not store anything, so the stored score is never updated. It should use the assignment operator =.
Q4
B — Python lists have no add() method. To store a new item in the list, use trusted.append("Sam").
Q5
B — win is not in quotes, so Python treats it as an undefined variable. The word to remove must be a string: remove("win").