Skip to Main Content
Ensemble Machine Learning Cookbook
book

Ensemble Machine Learning Cookbook

by Dipayan Sarkar, Vijayalakshmi Natarajan
January 2019
Beginner to intermediate content levelBeginner to intermediate
336 pages
7h 58m
English
Packt Publishing
Content preview from Ensemble Machine Learning Cookbook

How to do it...

Let's begin with training our models, and see how they perform in this section:

  1. Train the model using the Naive Bayes algorithm. Apply this algorithm to both the count data and the TF-IDF data.

The following is the code to train the Naive Bayes on the count data:

from sklearn.naive_bayes import MultinomialNBnb = MultinomialNB()nb.fit(count_train, Y_train)nb_pred_train = nb.predict(count_train)nb_pred_test = nb.predict(count_test)nb_pred_train_proba = nb.predict_proba(count_train)nb_pred_test_proba = nb.predict_proba(count_test)print('The accuracy for the training data is {}'.format(nb.score(count_train, Y_train)))print('The accuracy for the testing data is {}'.format(nb.score(count_test, Y_test)))

Take a look at the train ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Productive and Efficient Data Science with Python: With Modularizing, Memory profiles, and Parallel/GPU Processing

Productive and Efficient Data Science with Python: With Modularizing, Memory profiles, and Parallel/GPU Processing

Tirthajyoti Sarkar
Hands-On Automated Machine Learning

Hands-On Automated Machine Learning

Sibanjan Das, Umit Mert Cakmak

Publisher Resources

ISBN: 9781789136609Supplemental Content