April 2017
Beginner to intermediate
358 pages
9h 30m
English
Finally, we need to set up a classifier and we are using Naive Bayes for this chapter. As our dataset contains only binary features, we use the BernoulliNB classifier that is designed for binary features. As a classifier, it is very easy to use. As with DictVectorizer, we simply import it and add it to our pipeline:
from sklearn.naive_bayes import BernoulliNB
Now comes the moment to put all of these pieces together. In our Jupyter Notebook, set the filenames and load the dataset and classes as we have done before. Set the filenames for both the tweets themselves (not the IDs!) and the labels that we assigned to them. The code is as follows:
import osinput_filename = os.path.join(os.path.expanduser("~"), "Data", ...Read now
Unlock full access