CourseWare Wiki
Switch Term
Winter 2024 / 2025
Winter 2023 / 2024
Winter 2022 / 2023
Winter 2021 / 2022
Winter 2020 / 2021
Winter 2019 / 2020
Winter 2018 / 2019
Older
Search
Log In
old
courses
be5b33prg
homeworks
spam
step2
Warning
This page is located in archive. Go to the latest version of this
course pages
.
Differences
This shows you the differences between two versions of the page.
View differences:
Side by Side
Inline
Go
Link to this comparison view
Both sides previous revision
Previous revision
2015/12/04 14:22 svobodat [Specifications]
2015/12/01 16:04 xposik [Specifications]
2015/11/25 16:33 xposik [Preparation]
2015/11/25 16:30 xposik [Specifications]
2015/11/25 16:29 xposik [Preparation]
2015/11/25 16:00 xposik [Spam filter - step 2]
2015/11/25 15:59 xposik
2015/11/25 15:58 xposik
2015/11/25 15:57 xposik [Corpus]
2015/11/25 15:54 xposik [Preparation]
2015/10/15 14:59 xposik [Specifications]
2015/10/15 14:55 xposik [Corpus]
2015/10/15 14:50 xposik [Preparation]
2015/10/15 14:49 xposik [Spam filter - step 2]
2015/10/15 13:56 xposik created
Go
Next revision
Previous revision
2015/12/04 14:22 svobodat [Specifications]
2015/12/01 16:04 xposik [Specifications]
2015/11/25 16:33 xposik [Preparation]
2015/11/25 16:30 xposik [Specifications]
2015/11/25 16:29 xposik [Preparation]
2015/11/25 16:00 xposik [Spam filter - step 2]
2015/11/25 15:59 xposik
2015/11/25 15:58 xposik
2015/11/25 15:57 xposik [Corpus]
2015/11/25 15:54 xposik [Preparation]
2015/10/15 14:59 xposik [Specifications]
2015/10/15 14:55 xposik [Corpus]
2015/10/15 14:50 xposik [Preparation]
2015/10/15 14:49 xposik [Spam filter - step 2]
2015/10/15 13:56 xposik created
Go
Next revision
Both sides next revision
courses:be5b33prg:homeworks:spam:step2 [2015/11/25 16:00]
xposik
[Spam filter - step 2]
courses:be5b33prg:homeworks:spam:step2 [2015/11/25 16:33]
xposik
[Preparation]
Line 8:
Line 8:
* what these abbreviations mean for the spam filtering problem, and
* what these abbreviations mean for the spam filtering problem, and
* what we need to know to be able to compute them.
* what we need to know to be able to compute them.
+
* See the documentation for ''[[https://docs.python.org/3.4/library/collections.html#collections.namedtuple|namedtuple]]''.
+
+
===== Specifications =====
+
+
Task:
+
* In module ''quality.py'', create function ''compute_confusion_matrix()''.
+
* The function will have 4 input arguments:
+
* ''truth_dict'', a dictionary with the true correct class of individual emails,
+
* ''pred_dict'', a dictionary with the class predicted for individual emails by a filter,
+
* ''pos_tag'' (optional, with default value ''True''), a class that will be considered positive, and
+
* ''neg_tag'' (optional, with defualt value ''False''), a class that will be considered negative. Thanks to these optional parameters, the function will be generally usable, not only for the spam filter task with ''pos_tag="SPAM"'' and ''neg_tag="OK"'').
+
* The function will compute four statistics, TP, TN, FP, FN, needed to evaluate a filter, and will return them as a ''namedtuple'' with the following definition:<code python>
+
from collections import namedtuple
+
+
ConfMat = namedtuple('ConfMat', 'tp, tn fp fn')
+
</code>
+
+
Why do we need it?
+
* Function ''compute_confusion_matrix()'' represents the basis for evaluation of the filter performance.
+
* The function can be used in the following way:<code python>
+
>>> cm1 = compute_confusion_matrix({}, {})
+
>>> print(cm1)
+
ConfMat(tp=0, tn=0, fp=0, fn=0)
+
</code>or<code python>
+
>>> truth_dict = {'em1': 'SPAM', 'em2': 'SPAM', 'em3': 'OK', 'em4':'OK'}
+
>>> pred_dict = {'em1': 'SPAM', 'em2': 'OK', 'em3': 'OK', 'em4':'SPAM'}
+
>>> cm2 = compute_confusion_matrix(truth_dict, pred_dict, pos_tag='SPAM', neg_tag='OK')
+
>>> print(cm2)
+
ConfMat(tp=1, tn=1, fp=1, fn=1)
+
</code>
+
+
**Note**: You can expect that the dictionaries will have the same set of keys. Think about the situation when the keys would be different: what shall the method do?
+
+
>{{page>courses:be5b33prg:internal:homeworks:spam:step2#compute_confusion_matrix&editbtn}}
+
+
courses/be5b33prg/homeworks/spam/step2.txt
· Last modified: 2015/12/04 14:22 by
svobodat