text mining and text analytics the holdout sample will be used for our final test of the model and the creation of confusion matrix confusion matrix is way of checking how well model did on previously unseen data the matrix shows how many observations were correctly and incorrectly classified before creating or training and testing data we need to take one last steppouring the data into bag of words format where every term is given either "trueor "falselabel depending on its presence in that particular post we also need to do this for the unlabeled holdout sample our prepared data now contains every term for each vectoras shown in figure print prepared_data[ figure binary bag of words ready for modeling is very sparse data we created big but sparse matrixallowing us to apply techniques from if it was too big to handle on our machine with such small tablehoweverthere' no need for that now and we can proceed to shuffle and split the data into training and test set while the biggest part of your data should always go to the model trainingan optimal split ratio exists here we opted for - splitbut feel free to play with this the more observations you havethe more freedom you have here if you have few observations you'll need to allocate relatively more to training the model we're now ready to move on to the most rewarding partdata analysis step data analysis for our analysis we'll fit two classification algorithms to our datanaive bayes and decision trees naive bayes was explained in and decision tree earlier in this let' first test the performance of our naive bayes classifier nltk comes with classifierbut feel free to use algorithms from other packages such as scipy classifier nltk naivebayesclassifier train(trainwith the classifier trained we can use the test data to get measure on overall accuracy nltk classify accuracy(classifiertest