Knowledge Base

What are Naïve Bayes classifiers?

A Naïve Bayes classifier is a simple, fast algorithm for classifying data based on Bayes' theorem. It is a supervised machine learning algorithm that belongs to the statistical family of classifiers.

The word "Naïve" refers to the naïve assumption of feature independence: the model assumes that the value of one feature is not affected by, or dependent on, the presence or properties of any other feature.

Bayes' theorem

A Naïve Bayes classifier uses Bayes' theorem to calculate the probability of a specific event occurring given a specific set of feature values:

Bayes' theorem: the posterior probability equals the likelihood times the prior, divided by the evidence.

In this equation, P(target | predictor) is the predicted probability of the target given the predictor; P(predictor | target) is the probability of the predictor given the target; P(target) is the prior probability of the target value; and P(predictor) is the probability of the predictor value.

How a Naïve Bayes classifier works: a worked example

Suppose we have the following dataset of "Network Traffic" and "Network Failure" events, and we want to estimate the probability of a network failure occurring when network traffic is "very high". The tables below show the raw data, its frequency table, and the resulting likelihood table:

Three tables used by the Naïve Bayes calculation: the raw network-traffic dataset, a frequency table, and a likelihood table.

The calculation takes three steps. First, convert the raw data (Table 1) into a frequency table (Table 2) that counts each category of "Network Traffic" grouped by the target feature "Failure". Second, calculate the likelihood of each feature value across the whole dataset (Table 3). Third, substitute these values into Bayes' theorem:

Substituting the network-traffic likelihoods into Bayes' theorem gives a 0.71 probability of network failure.

This gives a high probability (71%) of network failure when network traffic is "very high". Using the same steps, the probability of no failure under very-high traffic is 0.29. The classifier chooses the class with the higher probability — here, network failure = yes.

Where Naïve Bayes is used

Because it is fast and performs well even with limited training data, Naïve Bayes is widely used for classification tasks such as spam filtering, document categorisation, and anomaly detection. In financial-markets infrastructure, the same probabilistic approach underpins tools such as Corvil network analytics, which classify and predict network behaviour from packet-level data. To learn how the accuracy of a classifier like this is measured, see What is a False Positive Rate?.