Warning
This page is located in archive.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
courses:be5b33prg:homeworks:spam:step1 [2015/10/15 14:48]
xposik [Preparation]
courses:be5b33prg:homeworks:spam:step1 [2015/11/26 09:13]
xposik [Specifications]
Line 50: Line 50:
 Function ''​read_classification_from_file()''​ (in module ''​utils.py''​) has to conform to the following specifications: ​ Function ''​read_classification_from_file()''​ (in module ''​utils.py''​) has to conform to the following specifications: ​
  
 +^ ''​read_classification_from_file(fpath)''​ ^^
 ^  Input  | The path to the text file (most likely either ''​!truth.txt''​ or ''​!prediction.txt''​) ​ | ^  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. ​ | ^  Output ​ | A dictionary containing either ''​SPAM''​ or ''​OK''​ label for each filename in email corpus. ​ |
Line 70: Line 71:
  
 > {{page>​courses:​a4b99rph:​internal:​cviceni:​spam:​tyden07#​read_classification_from_file&​editbtn}} > {{page>​courses:​a4b99rph:​internal:​cviceni:​spam:​tyden07#​read_classification_from_file&​editbtn}}
 +
 +
 +===== Writing classification (predictions) to a file =====
 +
 +Task:
 +  * In module ''​utils.py'',​ create function ''​write_classification_to_file()''​ that will write the (usually predicted) mail classes to a text file.
 +
 +Why do we need it:
 +  * The function will come handy when writing the filter; it can be used to create the ''​!prediction.txt''​ file. 
 +
 +==== Specifications ====
 +Function ''​write_classification_to_file()''​ (in module ''​utils.py''​) should conform to the following specifications: ​
 +
 +^ ''​write_classification_to_file(cls_dict,​ fpath)''​ ^^
 +^  Inputs ​ | (1) dictionary containing the email file names as keys, and email classes (''​SPAM''​ or ''​OK''​) as values.
 +^          | (2) The path to the text file that shall be created. ​ |
 +^  Output ​ | None.  |
 +
 +The following code
 +
 +<code python>
 +>>>​ cls_dict = {'​email1234':​ '​OK',​ '​email03':​ '​SPAM',​ '​email02':​ '​OK',​ '​email01':​ '​OK'​}
 +>>>​ fpath = '​1/​!prediction.txt'​
 +>>>​ write_classification_to_file(cls_dict,​ fpath)
 +</​code>​
 +
 +shall create file ''​!prediction.txt''​ in directory ''​1''​ (the directory must exist) with the following contents:
 +
 +<​code>​
 +email01 OK
 +email02 OK
 +email03 SPAM
 +email1234 OK
 +</​code>​
 +
 +The actual order of individual rows in the file is not important.
 +
 +If the ''​cls_dict''​ is empty, the function shall create an empty file.
 +
  
courses/be5b33prg/homeworks/spam/step1.txt ยท Last modified: 2015/11/30 15:29 by xposik