Skip to Content
Machine Learning with Python Cookbook, 2nd Edition
book

Machine Learning with Python Cookbook, 2nd Edition

by Kyle Gallatin, Chris Albon
August 2023
Intermediate to advanced
413 pages
8h 21m
English
O'Reilly Media, Inc.
Content preview from Machine Learning with Python Cookbook, 2nd Edition

Chapter 18. Naive Bayes

18.0 Introduction

Bayes’ theorem is the premier method for understanding the probability of some event, P ( A B ) , given some new information, P ( B A ) , and a prior belief in the probability of the event, P ( A ) :

P ( A B ) = P(BA)P(A) P(B)

The Bayesian method’s popularity has skyrocketed in the last decade, increasingly rivaling traditional frequentist applications in academia, government, and business. In machine learning, one application of Bayes’ theorem to classification comes in the form of the naive Bayes classifier. Naive Bayes classifiers combine a number of desirable qualities in practical machine learning into a single classifier. These include:

  • An intuitive approach

  • The ability to work with small data

  • Low computation costs for training and prediction

  • Often solid results in a variety of settings

Specifically, a naive Bayes classifier is based on:

P ( y x 1 , , x j ) = P(x 1 ,,x j y)P(y) P(x 1 ,,x j )

where:

  • P ( y x 1 , , x j ) is called the posterior and is the probability that an observation is class y given the observation’s values for the j features, x 1 , , x j .

  • P(x 1 ,,x j y) is called likelihood and is the likelihood of an observation’s values for features x 1 , , x j given their class, y.

  • P(y) is called the prior and is our belief for the probability of class y before looking at the data.

  • P(x 1 ,,x j ) is called the marginal probability.

In naive Bayes, ...

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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Machine Learning Engineering with Python - Second Edition

Machine Learning Engineering with Python - Second Edition

Andrew P. McMahon
Python Machine Learning - Third Edition

Python Machine Learning - Third Edition

Sebastian Raschka, Vahid Mirjalili
Introduction to Machine Learning with Python

Introduction to Machine Learning with Python

Andreas C. Müller, Sarah Guido

Publisher Resources

ISBN: 9781098135713Errata Page