Table of Contents

Spam filter - step 1

We are going to create a function, which can read the information from files !truth.txt or !prediction.txt into the dictionary data structure.

Preparation

Reading classification from a file

Task:

Why do we need it:

Specifications

Function read_classification_from_file() (in module utils.py) has to conform to the following specifications:

Input The path to the text file (most likely either !truth.txt or !prediction.txt)
Output A dictionary containing either SPAM or OK label for each filename in email corpus.

The function loads a text file contaning a pair of strings per line, separated by single space, like this:

email01 OK
email02 OK
email03 SPAM
email1234 OK
...
and creates a dictionary (the order of individual “rows” in the following listing is not important):
{'email1234': 'OK', 'email03': 'SPAM', 'email02': 'OK', 'email01': 'OK'}

If the file is empty, it returns an empty dictionary.