This is a question about the underpinnings of Ken Williams' AI-Categorizer:

http://search.cpan.org/~kwilliams/AI-Categorizer/

I don't understand something. I need your help.

This module has a Naive Bayes implementation. I tested this by training on about 1000 "ham" messages and 200 "spam" messages.

I then examined a number of test documents. I was interested in examining each WORD in those test documents to find those words that are most "spammy" and those that are most "hammy". So I iterated over an entire document and spit out the best_category and score for each word.

Strangely, many words which are very spam-like were assigned to the "ham" category and had high ham scores.

So, I then altered things and trained on equal numbers of spam and ham documents: 200 for each. When I retested, the spam-like words were now more likely to be labeled as spam.

I guess I don't understand...

Do these Naive Bayes filters require you to train on a corpus where the categories are exactly even in terms of documents examined? Or must I train on a corpus where the ratio of spam/ham matches the true rate of spam to ham that I receive in my email box?

I am thinking about a text classification problem beyond spam/ham where I only have fragmentary documents for one category, and many more docs for the other category. But, in a test scenario, the examined documents will be about 50/50... So I am unsure how to train a Bayes filter given the unequal cats in a corpus. I am not a Math person, so I have trouble understanding the underpinnings of all of this.

I want the Bayesian filter to assume that there is a 50/50 chance that a document is A or B. But in terms of training, I only have a handful of A documents, and many B documents.

Can you help?


In reply to Understanding Naive Bayesian classifiers by lokiloki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.