Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I want to build a document classifier in R, using the Naive Bayes approach.

Here are steps, that I've done so far:

  • I have corpus with about 30 documents from 2 authors (Classes are: "target author" and "other author").
  • "Vocabulary" (training set) has been pre-processed (removed numbers, removed punctuation, words to lower case, removed stop words, stem documents, strip whitespace), and I am considering only frequent words (top 700).
  • Now I have matrix which looks like:

    enter image description here

Then I trained my classifier using Bayes using some existing R library, e1071.

Here are my questions:

I want to test my classifier on other documents that were not part of the training set.

  • How to prepare my data matrix? What if those other documents don't contain all the words (attributes) from my training set? Should I put dummy columns there (e.g., with value=0)?
  • Does the position of the words (columns order) matter?

Here is an example:

Training attributes:

"wild"  "wind"  "woman"

Testing attributes:

"woman" "wind" "wild"  

Is this ok, or should columns be in the same order as in training matrix?

share|improve this question
"Classifying documents with Bayes" sounds like you'd like to resurrect the poor reverend and make him help you sort a pile of papers... – mbq Jan 13 '12 at 13:53

migrated from stackoverflow.com Jan 11 '12 at 21:22

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.