Each of 4601 email messages is described by the percentage of its words equal to a given word (or of its characters equal to a given character), for 54 words and characters, and labelled spam (1813 messages) or genuine email (2788). The left panel ranks the features by how differently they behave in the two classes; with the default settings its top eleven rows are the book's Table 1.1. The right panel plots two of these features for every message and shades the region where a hand-made rule says “spam”. The rule is scored on the book's training set (3065 messages) and test set (1536), with a cost for throwing away a good email.
Ranking: the absolute difference between the class means (as in Table 1.1), or the absolute two-sample t statistic, (meanspam − meanemail)/√(s2spam/nspam + s2email/nemail), which measures the difference in units of its standard error. Class means use all 4601 messages. Scatter: both axes on a square-root scale with a little random jitter so that the many zeros are visible; values beyond the 99th percentile sit on the edge. Tuning searches a = 0.05, 0.10, …, 3 and b = 0, 0.1, …, 8 for the smallest average cost on the training set.
code/ch01_introduction.py (class_mean_table, spam_rule, confusion, weighted_rule_search).