ArticleslgStudy

computer science

Naive Bayes classifier

Naive Bayes classifier is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Naive Bayes classifier rather than just read about it. In short: In statistics, naive (sometimes simple or idiot's) Bayes classifiers are a family of "probabilistic classifiers" which assume that the features are conditionally independent, given the target class. In other words, a naive Bayes model assumes the information about the class provided by each variable is unrelated to the information from the others, with no information shared between the predictors.

Naive Bayes classifier — main illustration
Naive Bayes classifier — illustration

Key takeaways

  • Naive Bayes classifier belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Naive Bayes classifier to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Naive Bayes classifier from memory before moving on to harder problems.

Reference excerpt

In statistics, naive (sometimes simple or idiot's) Bayes classifiers are a family of "probabilistic classifiers" which assume that the features are conditionally independent, given the target class. In other words, a naive Bayes model assumes the information about the class provided by each variable is unrelated to the information from the others, with no information shared between the predictors. The highly unrealistic nature of this assumption, called the naive independence assumption, is what gives the classifier its name. These classifiers are some of the simplest Bayesian network models. Naive Bayes classifiers generally perform worse than more advanced models like logistic regressions, especially at quantifying uncertainty (with naive Bayes models often producing wildly overconfident probabilities). However, they are highly scalable, requiring only one parameter for each feature or predictor in a learning problem. Maximum-likelihood training can be done by evaluating a closed-form expression (simply by counting observations in each group), rather than the expensive iterative approximation algorithms required by most other models. Despite the use of Bayes' theorem in the classifier's decision rule, naive Bayes is not (necessarily) a Bayesian method, and naive Bayes models can be fit to data using either Bayesian or frequentist methods.

Introduction Naive Bayes is a simple technique for constructing classifiers: models that assign class labels to problem instances, represented as vectors of feature values, where the class labels are drawn from some finite set. There is not a single algorithm for training such classifiers, but a family of algorithms based on a common principle: all naive Bayes classifiers assume that the value of a particular feature is independent of the value of any other feature, given the class variable. For example, a fruit may be considered to be an apple if it is red, round, and about 10 cm in diameter. A naive Bayes classifier considers each of these features to contribute independently to the probability that this fruit is an apple, regardless of any possible correlations between the color, roundness, and diameter features. In many practical applications, parameter estimation for naive Bayes models uses the method of maximum likelihood; in other words, one can work with the naive Bayes model without accepting Bayesian probability or using any Bayesian methods. Despite their naive design and apparently oversimplified assumptions, naive Bayes classifiers have worked quite well in many complex real-world situations. In 2004, an analysis of the Bayesian classification problem showed that there are sound theoretical reasons for the apparently implausible efficacy of naive Bayes classifiers. Still, a comprehensive comparison with other classification algorithms in 2006 showed that Bayes classification is outperformed by other approaches, such as boosted trees or random forests. An advantage of naive Bayes is that it only requires a small amount of training data to estimate the parameters necessary for classification.

Probabilistic model Abstractly, naive Bayes is a conditional probability model: it assigns probabilities p ( C k ∣ x 1 , … , x n ) {\displaystyle p(C_{k}\mid x_{1},\ldots ,x_{n})} for each of the K possible outcomes or classes C k {\displaystyle C_{k}} given a problem instance to be classified, represented by a vector x = ( x 1 , … , x n ) {\displaystyle \mathbf {x} =(x_{1},\ldots ,x_{n})} encoding some n features (independent variables). The problem with the above formulation is that if the number of features n is large or if a feature can take on a large number of values, then basing such a model on probability tables is infeasible. The model must therefore be reformulated to make it more tractable. Using Bayes' theorem, the conditional probability can be decomposed as:

p ( C k ∣ x ) = p ( C k ) p ( x ∣ C k ) p ( x ) {\displaystyle p(C_{k}\mid \mathbf {x} )={\frac {p(C_{k})\ p(\mathbf {x} \mid C_{k})}{p(\mathbf {x} )}}\,}

In plain English, using Bayesian probability terminology, the above equation can be written as

posterior = prior × likelihood evidence {\displaystyle {\text{posterior}}={\frac {{\text{prior}}\times {\text{likelihood}}}{\text{evidence}}}\,}

In practice, there is interest only in the numerator of that fraction, because the denominator does not depend on C {\displaystyle C} and the values of the features x i {\displaystyle x_{i}} are given, so that the denominator is effectively constant. The numerator is equivalent to the joint probability model

… excerpt ends here. Continue reading the full article.

Illustrations

Naive Bayes classifier: Example of a naive Bayes classifier depicted as a Bayesian network
Example of a naive Bayes classifier depicted as a Bayesian network
Naive Bayes classifier: Likelihood functions 
  
    
      
        p
        (
        
          x
        
        ∣
        Y
        )
      
    
    {\displaystyle p(\mathbf {x} \mid Y)}
  
, Confusion matrix and ROC curve. For the naive Bayes classifier and given that the a priori probabilities 
  
    
      
        p
        (
        Y
        )
      
    
    {\displaystyle p(Y)}
  
 are the same for all classes, then the decision boundary (green line) would be placed on the point where the two probability densities intersect, due to 
  
    
      
        p
        (
        Y
        ∣
        
          x
        
        )
        =
        
          
            
              p
              (
              Y
              )
               
              p
              (
              
                x
              
              ∣
              Y
              )
            
            
              p
              (
              
                x
              
              )
            
          
        
        ∝
        p
        (
        
          x
        
        ∣
        Y
        )
      
    
    {\displaystyle p(Y\mid \mathbf {x} )={\frac {p(Y)\ p(\mathbf {x} \mid Y)}{p(\mathbf {x} )}}\propto p(\mathbf {x} \mid Y)}
  
.
Likelihood functions p ( x ∣ Y ) {\displaystyle p(\mathbf {x} \mid Y)} , Confusion matrix and ROC curve. For the naive Bayes classifier and given that the a priori probabilities p ( Y ) {\displaystyle p(Y)} are the same for all classes, then the decision boundary (green line) would be placed on the point where the two probability densities intersect, due to p ( Y ∣ x ) = p ( Y )   p ( x ∣ Y ) p ( x ) ∝ p ( x ∣ Y ) {\displaystyle p(Y\mid \mathbf {x} )={\frac {p(Y)\ p(\mathbf {x} \mid Y)}{p(\mathbf {x} )}}\propto p(\mathbf {x} \mid Y)} .

Worked examples

Example 1 — a first encounter with Naive Bayes classifier

Start with the simplest possible case. Write down what Naive Bayes classifier claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Naive Bayes classifier before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Naive Bayes classifier ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Naive Bayes classifier

In research
Naive Bayes classifier appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Naive Bayes classifier in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Naive Bayes classifier is common in secondary-school and first-year university syllabi. It links to neighbouring topics Bayesian statistics, Classification algorithms, Machine learning algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Naive Bayes classifier outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Naive Bayes classifier” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Naive Bayes classifier in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Naive Bayes classifier means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Naive Bayes classifier out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Naive Bayes classifier in simple terms?

In statistics, naive (sometimes simple or idiot's) Bayes classifiers are a family of "probabilistic classifiers" which assume that the features are conditionally independent, given the target class. In other words, a naive Bayes model assumes the information about the class provided by each variabl…

Why does Naive Bayes classifier matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Naive Bayes classifier?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Naive Bayes classifier.

Tags

  • Bayesian statistics
  • Classification algorithms
  • Machine learning algorithms
  • Spamming
  • Statistical classification

Keep exploring