HOME

TheInfoList



OR:

In
statistics Statistics (from German language, German: ''wikt:Statistik#German, Statistik'', "description of a State (polity), state, a country") is the discipline that concerns the collection, organization, analysis, interpretation, and presentation of ...
, naive Bayes classifiers are a family of simple "
probabilistic classifier In machine learning, a probabilistic classifier is a classifier that is able to predict, given an observation of an input, a probability distribution over a set of classes, rather than only outputting the most likely class that the observation s ...
s" based on applying
Bayes' theorem In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule), named after Thomas Bayes, describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For examp ...
with strong (naive)
independence Independence is a condition of a person, nation, country, or state in which residents and population, or some portion thereof, exercise self-government, and usually sovereignty, over its territory. The opposite of independence is the statu ...
assumptions between the features (see Bayes classifier). They are among the simplest
Bayesian network A Bayesian network (also known as a Bayes network, Bayes net, belief network, or decision network) is a probabilistic graphical model that represents a set of variables and their conditional dependencies via a directed acyclic graph (DAG). Bay ...
models, but coupled with
kernel density estimation In statistics, kernel density estimation (KDE) is the application of kernel smoothing for probability density estimation, i.e., a non-parametric method to estimate the probability density function of a random variable based on ''kernels'' as w ...
, they can achieve high accuracy levels. Naive Bayes classifiers are highly scalable, requiring a number of parameters linear in the number of variables (features/predictors) in a learning problem.
Maximum-likelihood In statistics, maximum likelihood estimation (MLE) is a method of estimating the parameters of an assumed probability distribution, given some observed data. This is achieved by maximizing a likelihood function so that, under the assumed stati ...
training can be done by evaluating a
closed-form expression In mathematics, a closed-form expression is a mathematical expression that uses a finite number of standard operations. It may contain constants, variables, certain well-known operations (e.g., + − × ÷), and functions (e.g., ''n''th roo ...
, which takes
linear time In computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations performed by ...
, rather than by expensive iterative approximation as used for many other types of classifiers. In the
statistics Statistics (from German language, German: ''wikt:Statistik#German, Statistik'', "description of a State (polity), state, a country") is the discipline that concerns the collection, organization, analysis, interpretation, and presentation of ...
literature, naive Bayes models are known under a variety of names, including simple Bayes and independence Bayes. All these names reference the use of Bayes' theorem in the classifier's decision rule, but naive Bayes is not (necessarily) a
Bayesian Thomas Bayes (/beɪz/; c. 1701 – 1761) was an English statistician, philosopher, and Presbyterian minister. Bayesian () refers either to a range of concepts and approaches that relate to statistical methods based on Bayes' theorem, or a followe ...
method.


Introduction

Naive Bayes is a simple technique for constructing classifiers: models that assign class labels to problem instances, represented as vectors of
feature Feature may refer to: Computing * Feature (CAD), could be a hole, pocket, or notch * Feature (computer vision), could be an edge, corner or blob * Feature (software design) is an intentional distinguishing characteristic of a software item ...
values, where the class labels are drawn from some finite set. There is not a single
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
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 Independent or Independents may refer to: Arts, entertainment, and media Artist groups * Independents (artist group), a group of modernist painters based in the New Hope, Pennsylvania, area of the United States during the early 1930s * Independ ...
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 In statistics, correlation or dependence is any statistical relationship, whether causal or not, between two random variables or bivariate data. Although in the broadest sense, "correlation" may indicate any type of association, in statistics ...
between the color, roundness, and diameter features. In many practical applications, parameter estimation for naive Bayes models uses the method of
maximum likelihood In statistics, maximum likelihood estimation (MLE) is a method of estimation theory, estimating the Statistical parameter, parameters of an assumed probability distribution, given some observed data. This is achieved by Mathematical optimization, ...
; in other words, one can work with the naive Bayes model without accepting
Bayesian probability Bayesian probability is an Probability interpretations, interpretation of the concept of probability, in which, instead of frequentist probability, frequency or propensity probability, propensity of some phenomenon, probability is interpreted as re ...
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 Efficacy is the ability to perform a task to a satisfactory or expected degree. The word comes from the same roots as ''effectiveness'', and it has often been used synonymously, although in pharmacology a pragmatic clinical trial#Efficacy versu ...
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 Random forests or random decision forests is an ensemble learning method for classification, regression and other tasks that operates by constructing a multitude of decision trees at training time. For classification tasks, the output of t ...
. An advantage of naive Bayes is that it only requires a small number of training data to estimate the parameters necessary for classification.


Probabilistic model

Abstractly, naive Bayes is a
conditional probability In probability theory, conditional probability is a measure of the probability of an event occurring, given that another event (by assumption, presumption, assertion or evidence) has already occurred. This particular method relies on event B occur ...
model: given a problem instance to be classified, represented by a vector \mathbf = (x_1, \ldots, x_n) representing some features (independent variables), it assigns to this instance probabilities :p(C_k \mid x_1, \ldots, x_n)\, for each of possible outcomes or ''classes'' C_k. The problem with the above formulation is that if the number of features 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 In probability theory and statistics, Bayes' theorem (alternatively Bayes' law or Bayes' rule), named after Thomas Bayes, describes the probability of an event, based on prior knowledge of conditions that might be related to the event. For examp ...
, the conditional probability can be decomposed as :p(C_k \mid \mathbf) = \frac \, In plain English, using
Bayesian probability Bayesian probability is an Probability interpretations, interpretation of the concept of probability, in which, instead of frequentist probability, frequency or propensity probability, propensity of some phenomenon, probability is interpreted as re ...
terminology, the above equation can be written as :\text = \frac \, In practice, there is interest only in the numerator of that fraction, because the denominator does not depend on C and the values of the features x_i are given, so that the denominator is effectively constant. The numerator is equivalent to the
joint probability Given two random variables that are defined on the same probability space, the joint probability distribution is the corresponding probability distribution on all possible pairs of outputs. The joint distribution can just as well be considere ...
model :p(C_k, x_1, \ldots, x_n)\, which can be rewritten as follows, using the
chain rule In calculus, the chain rule is a formula that expresses the derivative of the composition of two differentiable functions and in terms of the derivatives of and . More precisely, if h=f\circ g is the function such that h(x)=f(g(x)) for every , ...
for repeated applications of the definition of
conditional probability In probability theory, conditional probability is a measure of the probability of an event occurring, given that another event (by assumption, presumption, assertion or evidence) has already occurred. This particular method relies on event B occur ...
: : \begin p(C_k, x_1, \ldots, x_n) & = p(x_1, \ldots, x_n, C_k) \\ & = p(x_1 \mid x_2, \ldots, x_n, C_k) \ p(x_2, \ldots, x_n, C_k) \\ & = p(x_1 \mid x_2, \ldots, x_n, C_k) \ p(x_2 \mid x_3, \ldots, x_n, C_k) \ p(x_3, \ldots, x_n, C_k) \\ & = \cdots \\ & = p(x_1 \mid x_2, \ldots, x_n, C_k) \ p(x_2 \mid x_3, \ldots, x_n, C_k) \cdots p(x_ \mid x_n, C_k) \ p(x_n \mid C_k) \ p(C_k) \\ \end Now the "naive"
conditional independence In probability theory, conditional independence describes situations wherein an observation is irrelevant or redundant when evaluating the certainty of a hypothesis. Conditional independence is usually formulated in terms of conditional probabil ...
assumptions come into play: assume that all features in \mathbf are
mutually independent Independence is a fundamental notion in probability theory, as in statistics and the theory of stochastic processes. Two events are independent, statistically independent, or stochastically independent if, informally speaking, the occurrence of o ...
, conditional on the category C_k. Under this assumption, :p(x_i \mid x_, \ldots ,x_, C_k ) = p(x_i \mid C_k)\,. Thus, the joint model can be expressed as : \begin p(C_k \mid x_1, \ldots, x_n) & \varpropto p(C_k, x_1, \ldots, x_n) \\ & \varpropto p(C_k) \ p(x_1 \mid C_k) \ p(x_2\mid C_k) \ p(x_3\mid C_k) \ \cdots \\ & \varpropto p(C_k) \prod_^n p(x_i \mid C_k)\,, \end where \varpropto denotes proportionality. This means that under the above independence assumptions, the conditional distribution over the class variable C is: :p(C_k \mid x_1, \ldots, x_n) = \frac p(C_k) \prod_^n p(x_i \mid C_k) where the evidence Z = p(\mathbf) = \sum_k p(C_k) \ p(\mathbf \mid C_k) is a scaling factor dependent only on x_1, \ldots, x_n, that is, a constant if the values of the feature variables are known.


Constructing a classifier from the probability model

The discussion so far has derived the independent feature model, that is, the naive Bayes
probability model A statistical model is a mathematical model that embodies a set of statistical assumptions concerning the generation of sample data (and similar data from a larger population). A statistical model represents, often in considerably idealized form, ...
. The naive Bayes classifier combines this model with a
decision rule In decision theory, a decision rule is a function which maps an observation to an appropriate action. Decision rules play an important role in the theory of statistics and economics, and are closely related to the concept of a strategy (game theory ...
. One common rule is to pick the hypothesis that is most probable so as to minimize the probability of misclassification; this is known as the '' maximum ''a posteriori'''' or ''MAP'' decision rule. The corresponding classifier, a Bayes classifier, is the function that assigns a class label \hat = C_k for some as follows: :\hat = \underset \ p(C_k) \displaystyle\prod_^n p(x_i \mid C_k).


Parameter estimation and event models

A class's prior may be calculated by assuming equiprobable classes (''i.e.'', p(C_k) = 1/K), or by calculating an estimate for the class probability from the training set (''i.e.'', = /). To estimate the parameters for a feature's distribution, one must assume a distribution or generate
nonparametric Nonparametric statistics is the branch of statistics that is not based solely on parametrized families of probability distributions (common examples of parameters are the mean and variance). Nonparametric statistics is based on either being dist ...
models for the features from the training set. The assumptions on distributions of features are called the "event model" of the naive Bayes classifier. For discrete features like the ones encountered in document classification (include spam filtering), multinomial and
Bernoulli Bernoulli can refer to: People *Bernoulli family of 17th and 18th century Swiss mathematicians: ** Daniel Bernoulli (1700–1782), developer of Bernoulli's principle **Jacob Bernoulli (1654–1705), also known as Jacques, after whom Bernoulli numbe ...
distributions are popular. These assumptions lead to two distinct models, which are often confused.


Gaussian naive Bayes

When dealing with continuous data, a typical assumption is that the continuous values associated with each class are distributed according to a
normal Normal(s) or The Normal(s) may refer to: Film and television * ''Normal'' (2003 film), starring Jessica Lange and Tom Wilkinson * ''Normal'' (2007 film), starring Carrie-Anne Moss, Kevin Zegers, Callum Keith Rennie, and Andrew Airlie * ''Norma ...
(or Gaussian) distribution. For example, suppose the training data contains a continuous attribute, x. The data is first segmented by the class, and then the mean and
variance In probability theory and statistics, variance is the expectation of the squared deviation of a random variable from its population mean or sample mean. Variance is a measure of dispersion, meaning it is a measure of how far a set of numbers ...
of x is computed in each class. Let \mu_k be the mean of the values in x associated with class ''Ck'', and let \sigma^2_k be the Bessel corrected variance of the values in x associated with class ''Ck''. Suppose one has collected some observation value v. Then, the probability ''density'' of v given a class C_k, p(x=v \mid C_k), can be computed by plugging v into the equation for a
normal distribution In statistics, a normal distribution or Gaussian distribution is a type of continuous probability distribution for a real-valued random variable. The general form of its probability density function is : f(x) = \frac e^ The parameter \mu ...
parameterized by \mu_k and \sigma^2_k. That is, : p(x=v \mid C_k)=\frac\,e^ Another common technique for handling continuous values is to use binning to discretize the feature values, to obtain a new set of Bernoulli-distributed features; some literature in fact suggests that this is necessary to apply naive Bayes, but it is not, and the discretization may throw away discriminative information. Sometimes the distribution of class-conditional marginal densities is far from normal. In these cases,
kernel density estimation In statistics, kernel density estimation (KDE) is the application of kernel smoothing for probability density estimation, i.e., a non-parametric method to estimate the probability density function of a random variable based on ''kernels'' as w ...
can be used for a more realistic estimate of the marginal densities of each class. This method, which was introduced by John and Langley, can boost the accuracy of the classifier considerably.


Multinomial naive Bayes

With a multinomial event model, samples (feature vectors) represent the frequencies with which certain events have been generated by a multinomial (p_1, \dots, p_n) where p_i is the probability that event occurs (or such multinomials in the multiclass case). A feature vector \mathbf = (x_1, \dots, x_n) is then a
histogram A histogram is an approximate representation of the distribution of numerical data. The term was first introduced by Karl Pearson. To construct a histogram, the first step is to " bin" (or "bucket") the range of values—that is, divide the ent ...
, with x_i counting the number of times event was observed in a particular instance. This is the event model typically used for document classification, with events representing the occurrence of a word in a single document (see
bag of words The bag-of-words model is a simplifying representation used in natural language processing and information retrieval (IR). In this model, a text (such as a sentence or a document) is represented as the bag (multiset) of its words, disregarding g ...
assumption). The likelihood of observing a histogram is given by : p(\mathbf \mid C_k) = \frac \prod_^n ^ The multinomial naive Bayes classifier becomes a
linear classifier In the field of machine learning, the goal of statistical classification is to use an object's characteristics to identify which class (or group) it belongs to. A linear classifier achieves this by making a classification decision based on the val ...
when expressed in log-space: : \begin \log p(C_k \mid \mathbf) & \varpropto \log \left( p(C_k) \prod_^n ^ \right) \\ & = \log p(C_k) + \sum_^n x_i \cdot \log p_ \\ & = b + \mathbf_k^\top \mathbf \end where b = \log p(C_k) and w_ = \log p_. If a given class and feature value never occur together in the training data, then the frequency-based probability estimate will be zero, because the probability estimate is directly proportional to the number of occurrences of a feature's value. This is problematic because it will wipe out all information in the other probabilities when they are multiplied. Therefore, it is often desirable to incorporate a small-sample correction, called
pseudocount In statistics, additive smoothing, also called Laplace smoothing or Lidstone smoothing, is a technique used to smooth categorical data. Given a set of observation counts \textstyle from a \textstyle -dimensional multinomial distribution wit ...
, in all probability estimates such that no probability is ever set to be exactly zero. This way of regularizing naive Bayes is called Laplace smoothing when the pseudocount is one, and
Lidstone smoothing In statistics, additive smoothing, also called Laplace smoothing or Lidstone smoothing, is a technique used to smooth categorical data. Given a set of observation counts \textstyle from a \textstyle -dimensional multinomial distribution with ...
in the general case. Rennie ''et al.'' discuss problems with the multinomial assumption in the context of document classification and possible ways to alleviate those problems, including the use of
tf–idf In information retrieval, tf–idf (also TF*IDF, TFIDF, TF–IDF, or Tf–idf), short for term frequency–inverse document frequency, is a numerical statistic that is intended to reflect how important a word is to a document in a collection or co ...
weights instead of raw term frequencies and document length normalization, to produce a naive Bayes classifier that is competitive with
support vector machine In machine learning, support vector machines (SVMs, also support vector networks) are supervised learning models with associated learning algorithms that analyze data for classification and regression analysis. Developed at AT&T Bell Laboratorie ...
s.


Bernoulli naive Bayes

In the multivariate
Bernoulli Bernoulli can refer to: People *Bernoulli family of 17th and 18th century Swiss mathematicians: ** Daniel Bernoulli (1700–1782), developer of Bernoulli's principle **Jacob Bernoulli (1654–1705), also known as Jacques, after whom Bernoulli numbe ...
event model, features are independent Booleans ( binary variables) describing inputs. Like the multinomial model, this model is popular for document classification tasks, where binary term occurrence features are used rather than term frequencies. If x_i is a boolean expressing the occurrence or absence of the 'th term from the vocabulary, then the likelihood of a document given a class C_k is given by : p(\mathbf \mid C_k) = \prod_^n p_^ (1 - p_)^ where p_ is the probability of class C_k generating the term x_i. This event model is especially popular for classifying short texts. It has the benefit of explicitly modelling the absence of terms. Note that a naive Bayes classifier with a Bernoulli event model is not the same as a multinomial NB classifier with frequency counts truncated to one.


Semi-supervised parameter estimation

Given a way to train a naive Bayes classifier from labeled data, it's possible to construct a semi-supervised training algorithm that can learn from a combination of labeled and unlabeled data by running the supervised learning algorithm in a loop: :Given a collection D = L \uplus U of labeled samples and unlabeled samples , start by training a naive Bayes classifier on . :Until convergence, do: ::Predict class probabilities P(C \mid x) for all examples in D. ::Re-train the model based on the ''probabilities'' (not the labels) predicted in the previous step. Convergence is determined based on improvement to the model likelihood P(D \mid \theta), where \theta denotes the parameters of the naive Bayes model. This training algorithm is an instance of the more general
expectation–maximization algorithm In statistics, an expectation–maximization (EM) algorithm is an iterative method to find (local) maximum likelihood or maximum a posteriori (MAP) estimates of parameters in statistical models, where the model depends on unobserved latent variabl ...
(EM): the prediction step inside the loop is the ''E''-step of EM, while the re-training of naive Bayes is the ''M''-step. The algorithm is formally justified by the assumption that the data are generated by a
mixture model In statistics, a mixture model is a probabilistic model for representing the presence of subpopulations within an overall population, without requiring that an observed data set should identify the sub-population to which an individual observation ...
, and the components of this mixture model are exactly the classes of the classification problem.


Discussion

Despite the fact that the far-reaching independence assumptions are often inaccurate, the naive Bayes classifier has several properties that make it surprisingly useful in practice. In particular, the decoupling of the class conditional feature distributions means that each distribution can be independently estimated as a one-dimensional distribution. This helps alleviate problems stemming from the
curse of dimensionality The curse of dimensionality refers to various phenomena that arise when analyzing and organizing data in high-dimensional spaces that do not occur in low-dimensional settings such as the three-dimensional physical space of everyday experience. The ...
, such as the need for data sets that scale exponentially with the number of features. While naive Bayes often fails to produce a good estimate for the correct class probabilities, this may not be a requirement for many applications. For example, the naive Bayes classifier will make the correct MAP decision rule classification so long as the correct class is predicted as more probable than any other class. This is true regardless of whether the probability estimate is slightly, or even grossly inaccurate. In this manner, the overall classifier can be robust enough to ignore serious deficiencies in its underlying naive probability model. Other reasons for the observed success of the naive Bayes classifier are discussed in the literature cited below.


Relation to logistic regression

In the case of discrete inputs (indicator or frequency features for discrete events), naive Bayes classifiers form a ''generative-discriminative'' pair with ( multinomial)
logistic regression In statistics, the logistic model (or logit model) is a statistical model that models the probability of an event taking place by having the log-odds for the event be a linear function (calculus), linear combination of one or more independent var ...
classifiers: each naive Bayes classifier can be considered a way of fitting a probability model that optimizes the joint likelihood p(C, \mathbf), while logistic regression fits the same probability model to optimize the conditional p(C \mid \mathbf). More formally, we have the following: The link between the two can be seen by observing that the decision function for naive Bayes (in the binary case) can be rewritten as "predict class C_1 if the
odds Odds provide a measure of the likelihood of a particular outcome. They are calculated as the ratio of the number of events that produce that outcome to the number that do not. Odds are commonly used in gambling and statistics. Odds also have ...
of p(C_1 \mid \mathbf) exceed those of p(C_2 \mid \mathbf)". Expressing this in log-space gives: : \log\frac = \log p(C_1 \mid \mathbf) - \log p(C_2 \mid \mathbf) > 0 The left-hand side of this equation is the log-odds, or ''
logit In statistics, the logit ( ) function is the quantile function associated with the standard logistic distribution. It has many uses in data analysis and machine learning, especially in data transformations. Mathematically, the logit is the ...
'', the quantity predicted by the linear model that underlies logistic regression. Since naive Bayes is also a linear model for the two "discrete" event models, it can be reparametrised as a linear function b + \mathbf^\top x > 0. Obtaining the probabilities is then a matter of applying the
logistic function A logistic function or logistic curve is a common S-shaped curve (sigmoid curve) with equation f(x) = \frac, where For values of x in the domain of real numbers from -\infty to +\infty, the S-curve shown on the right is obtained, with the ...
to b + \mathbf^\top x, or in the multiclass case, the
softmax function The softmax function, also known as softargmax or normalized exponential function, converts a vector of real numbers into a probability distribution of possible outcomes. It is a generalization of the logistic function to multiple dimensions, a ...
. Discriminative classifiers have lower asymptotic error than generative ones; however, research by Ng and
Jordan Jordan ( ar, الأردن; tr. ' ), officially the Hashemite Kingdom of Jordan,; tr. ' is a country in Western Asia. It is situated at the crossroads of Asia, Africa, and Europe, within the Levant region, on the East Bank of the Jordan Rive ...
has shown that in some practical cases naive Bayes can outperform logistic regression because it reaches its asymptotic error faster.


Examples


Person classification

Problem: classify whether a given person is a male or a female based on the measured features. The features include height, weight, and foot size. Although with NB classifier we treat them as independent, they are not in reality.


Training

Example training set below. The classifier created from the training set using a Gaussian distribution assumption would be (given variances are ''unbiased'' sample variances): The following example assumes equiprobable classes so that P(male)= P(female) = 0.5. This prior probability distribution might be based on prior knowledge of frequencies in the larger population or in the training set.


Testing

Below is a sample to be classified as male or female. In order to classify the sample, one has to determine which posterior is greater, male or female. For the classification as male the posterior is given by : \text = \frac For the classification as female the posterior is given by : \text = \frac The evidence (also termed normalizing constant) may be calculated: : \begin \text = P(\text) \, p(\text \mid \text) \, p(\text \mid \text) \, p(\text \mid \text) \\ + P(\text) \, p(\text \mid \text) \, p(\text \mid \text) \, p(\text \mid \text) \end However, given the sample, the evidence is a constant and thus scales both posteriors equally. It therefore does not affect classification and can be ignored. The probability distribution for the sex of the sample can now be determined: : P(\text) = 0.5 :p( \mid \text) = \frac\exp\left(\frac\right) \approx 1.5789, where \mu = 5.855 and \sigma^2 = 3.5033 \cdot 10^ are the parameters of normal distribution which have been previously determined from the training set. Note that a value greater than 1 is OK here – it is a probability density rather than a probability, because ''height'' is a continuous variable. : p( \mid \text) = \frac\exp\left(\frac\right) = 5.9881 \cdot 10^ : p( \mid \text) = \frac\exp\left(\frac\right) = 1.3112 \cdot 10^ : \text = \text = 6.1984 \cdot 10^ : P() = 0.5 : p( \mid ) = 2.23 \cdot 10^ : p( \mid ) = 1.6789 \cdot 10^ : p( \mid ) = 2.8669 \cdot 10^ : \text = \text = 5.3778 \cdot 10^ Since posterior numerator is greater in the female case, the prediction is that the sample is female.


Document classification

Here is a worked example of naive Bayesian classification to the
document classification Document classification or document categorization is a problem in library science, information science and computer science. The task is to assign a document to one or more classes or categories. This may be done "manually" (or "intellectually") ...
problem. Consider the problem of classifying documents by their content, for example into
spam Spam may refer to: * Spam (food), a canned pork meat product * Spamming, unsolicited or undesired electronic messages ** Email spam, unsolicited, undesired, or illegal email messages ** Messaging spam, spam targeting users of instant messaging ( ...
and non-spam
e-mail Electronic mail (email or e-mail) is a method of exchanging messages ("mail") between people using electronic devices. Email was thus conceived as the electronic ( digital) version of, or counterpart to, mail, at a time when "mail" meant ...
s. Imagine that documents are drawn from a number of classes of documents which can be modeled as sets of words where the (independent) probability that the i-th word of a given document occurs in a document from class ''C'' can be written as :p(w_i \mid C)\, (For this treatment, things are further simplified by assuming that words are randomly distributed in the document - that is, words are not dependent on the length of the document, position within the document with relation to other words, or other document-context.) Then the probability that a given document ''D'' contains all of the words w_i, given a class ''C'', is :p(D\mid C)=\prod_i p(w_i \mid C)\, The question that has to be answered is: "what is the probability that a given document ''D'' belongs to a given class ''C''?" In other words, what is p(C \mid D)\,? Now by definition :p(D\mid C)= and :p(C \mid D)= Bayes' theorem manipulates these into a statement of probability in terms of
likelihood The likelihood function (often simply called the likelihood) represents the probability of random variable realizations conditional on particular values of the statistical parameters. Thus, when evaluated on a given sample, the likelihood funct ...
. :p(C\mid D)=\frac Assume for the moment that there are only two mutually exclusive classes, ''S'' and ¬''S'' (e.g. spam and not spam), such that every element (email) is in either one or the other; :p(D\mid S)=\prod_i p(w_i \mid S)\, and :p(D\mid\neg S)=\prod_i p(w_i\mid\neg S)\, Using the Bayesian result above, one can write: :p(S\mid D)=\,\prod_i p(w_i \mid S) :p(\neg S\mid D)=\,\prod_i p(w_i \mid\neg S) Dividing one by the other gives: := Which can be re-factored as: :=\,\prod_i Thus, the probability ratio p(''S'' , ''D'') / p(¬''S'' , ''D'') can be expressed in terms of a series of likelihood ratios. The actual probability p(''S'' , ''D'') can be easily computed from log (p(''S'' , ''D'') / p(¬''S'' , ''D'')) based on the observation that p(''S'' , ''D'') + p(¬''S'' , ''D'') = 1. Taking the
logarithm In mathematics, the logarithm is the inverse function to exponentiation. That means the logarithm of a number  to the base  is the exponent to which must be raised, to produce . For example, since , the ''logarithm base'' 10 o ...
of all these ratios, one obtains: :\ln=\ln+\sum_i \ln (This technique of "
log-likelihood ratio In statistics, the likelihood-ratio test assesses the goodness of fit of two competing statistical models based on the ratio of their likelihoods, specifically one found by maximization over the entire parameter space and another found after im ...
s" is a common technique in statistics. In the case of two mutually exclusive alternatives (such as this example), the conversion of a log-likelihood ratio to a probability takes the form of a
sigmoid curve A sigmoid function is a mathematical function having a characteristic "S"-shaped curve or sigmoid curve. A common example of a sigmoid function is the logistic function shown in the first figure and defined by the formula: :S(x) = \frac = \ ...
: see
logit In statistics, the logit ( ) function is the quantile function associated with the standard logistic distribution. It has many uses in data analysis and machine learning, especially in data transformations. Mathematically, the logit is the ...
for details.) Finally, the document can be classified as follows. It is spam if p(S\mid D) > p(\neg S\mid D) (i. e., \ln > 0), otherwise it is not spam.


See also

*
AODE Averaged one-dependence estimators (AODE) is a probabilistic classification learning technique. It was developed to address the attribute-independence problem of the popular naive Bayes classifier. It frequently develops substantially more accur ...
* Bayes classifier *
Bayesian spam filtering Naive Bayes classifiers are a popular statistical technique of e-mail filtering. They typically use bag-of-words features to identify email spam, an approach commonly used in text classification. Naive Bayes classifiers work by correlating th ...
*
Bayesian network A Bayesian network (also known as a Bayes network, Bayes net, belief network, or decision network) is a probabilistic graphical model that represents a set of variables and their conditional dependencies via a directed acyclic graph (DAG). Bay ...
* Random naive Bayes *
Linear classifier In the field of machine learning, the goal of statistical classification is to use an object's characteristics to identify which class (or group) it belongs to. A linear classifier achieves this by making a classification decision based on the val ...
*
Logistic regression In statistics, the logistic model (or logit model) is a statistical model that models the probability of an event taking place by having the log-odds for the event be a linear function (calculus), linear combination of one or more independent var ...
*
Perceptron In machine learning, the perceptron (or McCulloch-Pitts neuron) is an algorithm for supervised learning of binary classifiers. A binary classifier is a function which can decide whether or not an input, represented by a vector of numbers, belon ...
*
Take-the-best heuristic In psychology, the take-the-best heuristic is a heuristic (a simple strategy for decision-making) which decides between two alternatives by choosing based on the first cue that discriminates them, where cues are ordered by cue validity (highest ...


References


Further reading

* * * * * {{cite conference , last1=Minsky , first1=M. , author-link=Marvin Minsky , year=1961 , title=Steps toward Artificial Intelligence , conference=Proc. IRE , volume=49 , issue=1 , pages = 8–30


External links


Book Chapter: Naive Bayes text classification, Introduction to Information Retrieval

Naive Bayes for Text Classification with Unbalanced Classes

Benchmark results of Naive Bayes implementations

Hierarchical Naive Bayes Classifiers for uncertain data
(an extension of the Naive Bayes classifier). ;Software * Naive Bayes classifiers are available in many general-purpose machine learning and NLP packages, including
Apache Mahout Apache Mahout is a project of the Apache Software Foundation to produce free implementations of distributed or otherwise scalable machine learning algorithms focused primarily on linear algebra. In the past, many of the implementations use the ...

Mallet
NLTK The Natural Language Toolkit, or more commonly NLTK, is a suite of libraries and programs for symbolic and statistical natural language processing (NLP) for English written in the Python programming language. It was developed by Steven Bird and E ...
,
Orange Orange most often refers to: *Orange (fruit), the fruit of the tree species '' Citrus'' × ''sinensis'' ** Orange blossom, its fragrant flower *Orange (colour), from the color of an orange, occurs between red and yellow in the visible spectrum * ...
,
scikit-learn scikit-learn (formerly scikits.learn and also known as sklearn) is a free software machine learning library for the Python programming language. It features various classification, regression and clustering algorithms including support-vector ...
and
Weka The weka, also known as the Māori hen or woodhen (''Gallirallus australis'') is a flightless bird species of the rail family. It is endemic to New Zealand. It is the only extant member of the genus '' Gallirallus''. Four subspecies are recogni ...
. *
IMSL Numerical Libraries IMSL (International Mathematics and Statistics Library) is a commercial collection of software libraries of numerical analysis functionality that are implemented in the computer programming languages C, Java, C#.NET, and Fortran. A Python int ...
Collections of math and statistical algorithms available in C/C++, Fortran, Java and C#/.NET. Data mining routines in the IMSL Libraries include a Naive Bayes classifier. * An interactive
Microsoft Excel Microsoft Excel is a spreadsheet developed by Microsoft for Microsoft Windows, Windows, macOS, Android (operating system), Android and iOS. It features calculation or computation capabilities, graphing tools, pivot tables, and a macro (comp ...
spreadshee
Naive Bayes implementation
using VBA (requires enabled macros) with viewable source code.
jBNC - Bayesian Network Classifier Toolbox

Statistical Pattern Recognition Toolbox for Matlab

ifile
- the first freely available (Naive) Bayesian mail/spam filter
NClassifier
- NClassifier is a .NET library that supports text classification and text summarization. It is a port of Classifier4J.
Classifier4J
- Classifier4J is a Java library designed to do text classification. It comes with an implementation of a Bayesian classifier.
JNBC
Naive Bayes Classifier running in-memory or using fast key-value stores (MapDB, LevelDB or RocksDB).
Blayze
- Blayze is a minimal JVM library for Naive Bayes classification written in Kotlin. Classification algorithms Statistical classification Bayesian statistics