February 2019
Beginner to intermediate
382 pages
10h 1m
English
Coding from scratch and implementing on your own solutions is the best way to learn about machine learning model. Of course, we can take a shortcut by directly using the MultinomialNB class from the scikit-learn API:
>>> from sklearn.naive_bayes import MultinomialNB
Let's initialize a model with a smoothing factor (specified as alpha in scikit-learn) of 1.0, and prior learned from the training set (specified as fit_prior in scikit-learn):
>>> clf = MultinomialNB(alpha=1.0, fit_prior=True)
To train the Naïve Bayes classifier with the fit method, use the following command:
>>> clf.fit(term_docs_train, Y_train)
And to obtain the prediction results with the predict_proba method, use the following commands: ...
Read now
Unlock full access