# AI News, Machine Learning FAQ

- On Saturday, June 30, 2018
- By Read More

## Machine Learning FAQ

In favor of discriminative models, Vapnik wrote once “one should solve the classification problem directly and never solve a more general problem as an intermediate step”. (Vapnik,

On small datasets you’d might want to try out naive Bayes, but as your training set size grows, you likely get better results with logistic regression.

- On Saturday, June 30, 2018
- By Read More

## Naive Bayes classifier

In machine learning, naive Bayes classifiers are a family of simple 'probabilistic classifiers' based on applying Bayes' theorem with strong (naive) independence assumptions between the features.

It was introduced under a different name into the text retrieval community in the early 1960s,[1]:488 and remains a popular (baseline) method for text categorization, the problem of judging documents as belonging to one category or the other (such as spam or legitimate, sports or politics, etc.) with word frequencies as the features.

With appropriate pre-processing, it is competitive in this domain with more advanced methods including support vector machines.[2] It also finds application in automatic medical diagnosis.[3] 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 training can be done by evaluating a closed-form expression,[1]:718 which takes linear time, rather than by expensive iterative approximation as used for many other types of classifiers.

In the statistics and computer science literature, naive Bayes models are known under a variety of names, including simple Bayes and independence Bayes.[4] All these names reference the use of Bayes' theorem in the classifier's decision rule, but naive Bayes is not (necessarily) a Bayesian method.[1][4]

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.

It 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.

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.

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.[5] 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.[6] An advantage of naive Bayes is that it only requires a small number of training data to estimate the parameters necessary for classification.[citation needed] Abstractly, naive Bayes is a conditional probability model: given a problem instance to be classified, represented by a vector

1

n

representing some n features (independent variables), it assigns to this instance probabilities for each of K possible outcomes or classes

k

.[7] 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.

Using Bayes' theorem, the conditional probability can be decomposed as In plain English, using Bayesian probability terminology, the above equation can be written as In practice, there is interest only in the numerator of that fraction, because the denominator does not depend on

i

The numerator is equivalent to the joint probability model which can be rewritten as follows, using the chain rule for repeated applications of the definition of conditional probability: Now the 'naive' conditional independence assumptions come into play: assume that each feature

i

j

k

k

k

k

1

n

y

^

k

class's prior may be calculated by assuming equiprobable classes (i.e., priors = 1 / (number of classes)), or by calculating an estimate for the class probability from the training set (i.e., (prior for a given class) = (number of samples in the class) / (total number of samples)).

To estimate the parameters for a feature's distribution, one must assume a distribution or generate nonparametric models for the features from the training set.[8] 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 distributions are popular.

These assumptions lead to two distinct models, which are often confused.[9][10] When dealing with continuous data, a typical assumption is that the continuous values associated with each class are distributed according to a Gaussian distribution.

k

k

2

k

k

k

k

2

That is, 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.[4] With a multinomial event model, samples (feature vectors) represent the frequencies with which certain events have been generated by a multinomial

1

n

i

1

n

i

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 assumption).

The likelihood of observing a histogram x is given by The multinomial naive Bayes classifier becomes a linear classifier when expressed in log-space:[2] where

k

k

i

k

i

If a given class and feature value never occur together in the training data, then the frequency-based probability estimate will be zero.

Therefore, it is often desirable to incorporate a small-sample correction, called pseudocount, in all probability estimates such that no probability is ever set to be exactly zero.

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 weights instead of raw term frequencies and document length normalization, to produce a naive Bayes classifier that is competitive with support vector machines.[2] In the multivariate Bernoulli event model, features are independent booleans (binary variables) describing inputs.

Like the multinomial model, this model is popular for document classification tasks,[9] where binary term occurrence features are used rather than term frequencies.

i

is a boolean expressing the occurrence or absence of the i'th term from the vocabulary, then the likelihood of a document given a class

k

k

i

k

i

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:[11] Convergence is determined based on improvement to the model likelihood

This training algorithm is an instance of the more general expectation–maximization algorithm (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, and the components of this mixture model are exactly the classes of the classification problem.[11] 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, such as the need for data sets that scale exponentially with the number of features.

For example, the naive Bayes classifier will make the correct MAP decision rule classification so long as the correct class is more probable than any other class.

In this manner, the overall classifier can be robust enough to ignore serious deficiencies in its underlying naive probability model.[3] Other reasons for the observed success of the naive Bayes classifier are discussed in the literature cited below.

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 classifiers: each naive Bayes classifier can be considered a way of fitting a probability model that optimizes the joint likelihood

.[13] 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

1

1

2

Expressing this in log-space gives: The left-hand side of this equation is the log-odds, or logit, the quantity predicted by the linear model that underlies logistic regression.

w

⊤

w

⊤

however, research by Ng and Jordan has shown that in some practical cases naive Bayes can outperform logistic regression because it reaches its asymptotic error faster.[13] Problem: classify whether a given person is a male or a female based on the measured features.

The classifier created from the training set using a Gaussian distribution assumption would be (given variances are unbiased sample variances): Let's say we have equiprobable classes so P(male)= P(female) = 0.5.

This prior probability distribution might be based on our knowledge of frequencies in the larger population, or on frequency in the training set.

For the classification as male the posterior is given by For the classification as female the posterior is given by The evidence (also termed normalizing constant) may be calculated: However, given the sample, the evidence is a constant and thus scales both posteriors equally.

2

−

2

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 (For this treatment, we simplify things further 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

i

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: see logit for details.) Finally, the document can be classified as follows.

p

(

S

∣

D

)

p

(

¬

S

∣

D

)

- On Monday, September 16, 2019

**Andrew Ng Naive Bayes Generative Learning Algorithms**

This set of videos come from Andrew Ng's courses on Stanford OpenClassroom at ..

**(ML 1.5) Generative vs discriminative models**

A broad overview. A playlist of these Machine Learning videos is available here:

**How Naive Bayes Classifier Works 1/2.. Understanding Naive Bayes and Example**

My web page:

**IAML2.23: Generative vs. discriminative learning**

**Lecture 22 (Fisher LDA & Bayesian Classification)**

Learning Theory (Reza Shadmehr, PhD) Fisher linear discriminant, classification using posterior probabilities with explicit models of densities, confidence and ...

**Difference between Classification and Regression - Georgia Tech - Machine Learning**

Watch on Udacity: Check out the full Advanced Operating Systems course for free ..

**Mod-01 Lec-07 Normal Density and Discriminant Function**

Pattern Recognition and Application by Prof. P.K. Biswas,Department of Electronics & Communication Engineering,IIT Kharagpur.For more details on NPTEL ...

**(ML 8.1) Naive Bayes classification**

An introduction to "naive Bayes" classifiers, in which we model the features as conditionally independent given the class.

**Machine Learning: Multiclass Classification**

How to turn binary classifiers into multiclass classifiers.