November 2017
Intermediate to advanced
374 pages
10h 19m
English
In this recipe, we'll use Naive Bayes to do document classification with sklearn. An example I have personal experience of is using a word that makes up an account descriptor in accounting, such as accounts payable, and determining if it belongs to the income statement, cash flow statement, or balance sheet.
The basic idea is to use the word frequency from a labeled test corpus to learn the classifications of the documents. Then, we can turn it on a training set and attempt to predict the label.
We'll use the newgroups dataset within sklearn to play with the Naive Bayes model. It's a non-trivial amount of data, so we'll fetch it instead of loading it. We'll also limit the categories to rec.autos and rec.motorcycles:
import numpy ...
Read now
Unlock full access