the specialized class naivebayesclassifier also did some heavy lifting for us in the background so we could not appreciate the innards by which the algorithm arrived at the various predictions our next example will use the scikit module to predict the category that phrase may belong to supervised learning example assume that we have set of posts to categorize as with supervised learningwe need to first train the model in order for it to accurately predict the category of an unknown post gathering data the scikit module comes with number of sample data we will use for training our model in this casewe will use the newsgroups posts to load the postswe will use the following lines of codefrom sklearn datasets import fetch_ newsgroups training_data fetch_ newsgroups(subset='train'categories=categoriesshuffle=truerandom_state= after we have trained our modelthe results of prediction must belong to one of the following categoriescategories ['alt atheism''soc religion christian','comp graphics''sci med'the number of records we are going to use as training data is obtained by the followingprint(len(training_data)machine learning algorithms do not mix well with textual attributes so the categories that each post belongs to are presented as numbersprint(set(training_data target)the categories have integer values that we can map back to the categories themselves with print(training_data target_names[ ]here is numerical random index picked from set(training_data target