Skip to main content
Journal of Cheminformatics logoLink to Journal of Cheminformatics
. 2013 Aug 23;5:37. doi: 10.1186/1758-2946-5-37

Full “Laplacianised” posterior naive Bayesian algorithm

Hamse Y Mussa 1,, John BO Mitchell 2, Robert C Glen 1
PMCID: PMC3846418  PMID: 23968281

Abstract

Background

In the last decade the standard Naive Bayes (SNB) algorithm has been widely employed in multi–class classification problems in cheminformatics. This popularity is mainly due to the fact that the algorithm is simple to implement and in many cases yields respectable classification results. Using clever heuristic arguments “anchored” by insightful cheminformatics knowledge, Xia et al. have simplified the SNB algorithm further and termed it the Laplacian Corrected Modified Naive Bayes (LCMNB) approach, which has been widely used in cheminformatics since its publication.

In this note we mathematically illustrate the conditions under which Xia et al.’s simplification holds. It is our hope that this clarification could help Naive Bayes practitioners in deciding when it is appropriate to employ the LCMNB algorithm to classify large chemical datasets.

Results

A general formulation that subsumes the simplified Naive Bayes version is presented. Unlike the widely used NB method, the Standard Naive Bayes description presented in this work is discriminative (not generative) in nature, which may lead to possible further applications of the SNB method.

Conclusions

Starting from a standard Naive Bayes (SNB) algorithm, we have derived mathematically the relationship between Xia et al.’s ingenious, but heuristic algorithm, and the SNB approach. We have also demonstrated the conditions under which Xia et al.’s crucial assumptions hold. We therefore hope that the new insight and recommendations provided can be found useful by the cheminformatics community.

Keywords: Naive Bayes, Laplacian Corrected Modified Naive Bayes, Classifications, Cheminformatics

Background

Broadly speaking there are two conceptually different ways to solve statistical problems: the frequentist and the Bayesian approaches. On the pros and cons of each method there are numerous excellent review articles and text books, such as the recent book by Murphy [1]. Unlike the frequentist approach, in the Bayesian approach any a priori knowledge about the probability distribution function that one assumes might have generated the given data (in the first place) can be taken into account when estimating this distribution function from the data at hand. If the data are noise–free and “complete”, the role of the a priori information in estimating the distribution function diminishes drastically. However, the a priori information can be crucial when the data are noisy and sparse. The latter scenario is typical in realistic large chemical datasets, which, arguably, makes Bayesian based statistics a powerful data analysis tool.

Unfortunately, Bayesian statistics in its fullest form is not computationally feasible in realistic cheminformatics data analyses. However, in recent years, a simplified version of the Bayesian approach, which is commonly known as the “Naive” Bayesian algorithm, has been found to be a useful classification tool in multi–class classification problems in cheminformactics. To this end a Naive Bayesian classifier is built on binary descriptor space. The descriptors/features xj, representing the compounds to be classified, assume binary values 0 or 1, where (j = 1,2,...,L) and L can typically be more than 1,000. Thus for some cheminformatics practitioners even the Naive Bayesian algorithm in its standard form is computationally prohibitive when the dataset is large. In this regard, Xia et al. [2] proposed a simpler version of the standard Naive Bayesian algorithm, albeit for binary classification problems; slight variants of this algorithm for multi–class classification can also be found in [3,4]. According to Rogers et al.[5], Rogers being a co–author of the work presented in [2], “the standard Naive Bayes was modified by considering only the effect of the presence of a feature and not its absence”. There are also a few more noticeable aspects of this proposed simplification: (a) the authors cleverly estimate directly – albeit heuristically – the a posteriori class probability for the present feature; (b) these authors (rather ingeniously) incorporate a Laplacian–correction into the estimated posterior class probability; and (c) the authors deem absent features not discriminating enough and therefore discard their contributions to the estimation of the posterior class. More than anything else it is this omission of the absent features from the Standard Naive Bayes (SNB) algorithm that makes Xia et al.’s proposed Naive Bayes Algorithm, termed Laplacian Corrected Modified Naive Bayes (LCMNB), (and its variants by different groups) computationally fast.

It is these three points, (a), (b) and (c), that we expound on in a mathematical setting to demonstrate under which conditions they hold – not only in an abstract sense, but also in the practical sense for a NB practitioner to make an informed decision as to when it is appropriate to employ SNB or LCMNB, in the cheminformatics context.

Methods

Naive Bayes

From Bayes’ theorem recall that [6]:

p(ωi|x)p(ωi)=p(x|ωi)p(x) (1)

where x = (x1,x2,...,xL) and ωi denote the feature vectors and class labels, respectively; xj and L being as described before, whereas i is just an index for the class labels. The terms p(ωi|x), p(x|ωi), p(ωi), and p(x) refer to the posterior probability for ωi given x, the descriptor vector distribution conditioned on class ωi, the a priori probability of class ωi occurring, and the descriptor vector density function, respectively – for more details, see ref. [3,4,6].

The left hand side of Eq. 1 can be expressed as follows [1,7]

p(ωi|x)p(ωi)=p(ωi|x1,x2,...,xL)p(ωi) (2)

By virtue of Bayes’ theorem p(ωi|x1,x2,...,xL) can be rewritten as

p(ωi|x1,x2,...,xL)=p(x1,x2,...,xL|ωi)p(ωi)p(x1,x2,...,xL) (3)

which in turn allows us to rewrite Eq. 2 as

p(ωi|x)p(ωi)=p(ωi)p(x1,x2,...,xL|ωi)p(ωi)p(x1,x2,...,xL)=p(x1,x2,...,xL|ωi)p(x1,x2,...,xL) (4)

Making use of the chain rule of probability [1,8], we can express p(x1,x2,...,xL|ωi) as

p(x1,x2,...,xL|ωi)=p(x1|ωi)p(x2|ωi,x1).....p(xL|ωi,x1,x2,...,xL1) (5)

Plugging the right hand side of the equation above into Eq. 4 results in

p(ωi|x)p(ωi)=p(x1|ωi)p(x2|ωi,x1).....p(xL|ωi,x1,x2,...,xL1)p(x1,x2,...,xL) (6)

In practice, it is extremely difficult to estimate p(ωi|x) or p(x|ωi). This reality inevitably forces one to make concessions over the degree of accuracy the estimated p(ωi|x) or p(x|ωi) can deliver. One widely employed scheme to obtain these probability distributions with compromised accuracy is to assume that individual descriptors xj, j = 1,2,...,L, are independent conditional on ωi. It is this naive assumption of independence among features to which the term “Naive” in “Naive Bayesian” refers.

Under this naive assumption, in Eq. 6, p(x2|ωi) = p(x2|ωi,x1), p(x3|ωi) = p(x3|ωi,x1,x2),..., p(xL|ωi) = p(xL|ωi,x1,x2...,xL−1). Thus, Eq. 6 modifies to

p(ωi|x)p(ωi)=p(x1|ωi)p(x2|ωi)...p(xL|ωi)p(x1,x2,...,xL) (7)

Multiplying top and bottom of Eq. 7 by pL(ωi)Πj=1Lp(xj) yields

p(ωi|x)p(ωi)=pL(ωi)p(x1|ωi)p(x2|ωi)...p(xL|ωi)Πj=1Lp(xj)pL(ωi)p(x1,x2,...,xL)Πj=1Lp(xj) (8)
=pL(ωi)p(x1|ωi)p(x2|ωi)...p(xL|ωi)Πj=1Lp(xj)Πj=1Lp(xj)pL(ωi)p(x1,x2,...,xL) (9)

Then making use of the fact that p(ωi|x1)=p(ωi)p(x1|ωi)p(x1), p(ωi|x2)=p(ωi)p(x2|ωi)p(x2),..., p(ωi|xL)=p(ωi)p(xL|ωi)p(x1), we can rewrite Eq. 9 as

p(ωi|x)p(ωi)=p(ωi|x1)p(ωi|x2)...p(ωi|xL)Πj=1Lp(xj)pL(ωi)p(x1,x2,...,xL) (10)

or more compactly as

p(ωi|x)p(ωi)=Πj=1Lp(ωi|xj)pL(ωi)×Πj=1Lp(xj)p(x1,x2,....,xL) (11)

Clearly Πj=1Lp(xj)p(x1,x2,....,xL) is common to all classes and therefore plays no role in classification. Thus, in practice (in the Naive Bayes context with which this work is concerned) one is required to estimate p(ωi|xj) and p(ωi).

Since generative approaches can be informative and “simpler” than their discriminative counterparts [9], we make use of Bayes’ theorem again, i.e., p(ωi|xj)=p(ωi)p(xj|ωi)p(xj) and then estimate p(ωi|xj) through p(ωi)p(xj|ωi)p(xj), where p(xj)=i=1Cp(xj|ωi)p(ωi) with C referring to the number of classes. p(ωi) denotes the a priori class probability, which is relatively easy to estimate. Thus, in our Bayesian context, the estimation of p(ωj|xj) boils down in practice to estimating p(xj|ωi).

Estimation of p(xj|ωi), with xj = 1 and 0

p(xj|ωi) can be estimated using the given data and assuming a Beta distribution as an a priori distribution for p(xj|ωi) [10]. (There are other possible prior distributions from which one can choose, but we select the Beta distribution for reasons that will transpire later). As described in Appedix A, a Beta a priori distribution Beta(αi,βi) for p(xj|ωi) results in a p(xj|ωi) estimator in the form [11]:

p(xj=1|ωi)=Nij+αiNωi+βi+αi (12)

and of course

p(xj=0|ωi)=1Nij+αiNωi+βi+αi (13)

where Nωi and Nij, respectively, denote the number compounds in class ωi, and number of compounds in this class with descriptor xj assuming value 1. βi and αi are Beta distribution hyper–parameters per class and the valid range of values that these hyper–parameter can assume are as defined in Appendix A. When αi and βi equal 1, αi and βi + αi in Eqs. 12–13 can be viewed as a “Laplacian correction”.

Results and discussion

Estimation of p(ωi|xj = 1) and p(ωi|xj = 0)

Estimation of p(ωi|xj = 1): In Our Approach

Remark 1

Assume that we have N chemical compounds (and their activity labels) available for training, where Nωi of these compounds belong to class ωi.

Remark 2

Assume that the class a priori distribution is taken as p(ωi)=NωiN, where Nωi>>αi+βi (which is a valid assumption as found in any realistic large chemical dataset).

By virtue of Remark 1 and Eq. 12, the estimate of p(ωi|xj = 1) becomes

p(ωi|xj=1)=p(xj=1|ωi)p(ωi)p(xj=1)=Nij+αiNωi+αi+βi×NωiNi=1CNij+αiNωi+αi+βi×NωiN (14)

(recall that p(xj)=i=1Cp(xj|ωi)p(ωi)).

Because of Remark 2, Eq. 14 can be simplified to

p(ωi|xj=1)=Nij+αii=1CNij+i=1Cαi=Nij+αiNj++i=1Cαi (15)

where Nj+ is the number of times xj assumes the value 1.

Estimation of p(ωi|xj = 1): In Xia et al.’s Formulation

In the approach of Xia et al., p(ωi|xj = 1) is estimated as

p(ωi|xj=1)=Nij+AiNj++K (16)

where K is as defined in Xia et al. and in their paper Ai is given as

Ai=p(ωi)×K,withK=i=1CAiasi=1Cp(ωi)=1 ()

Eq. 16 constitutes what Xia et al. term “the Laplacian–Corrected Modified Naive Bayes (LCMNB)” estimator for p(ωi|xj = 1).

If αi in Eq. 15 is set to Ai, Eq. 15 is exactly equivalent to Xia et al.’s estimator for p(ωi|xj = 1) as can be seen in Eq. 16.

We note in passing that in Xia et al.’s case, C = 2 and p(ω2)=1K, which in their nomenclature denoted by p(Active) – that is, A2 = 1 while A1 = K − 1.

Initially we employed the Beta a priori distribution for the class conditional distribution to ascertain the equivalence of Eqs. 15 and 16. Fortunately, however, we have ended up with the general equations (Eqs. 14 – 15) that not only encapsulate the LCMNB scheme of Xia et al., but also subsume the other various variants of LCMNB, such as those discussed in Nidhi et al. and Nigsch et al.’s papers [3,4].

At any rate, let us proceed to the nub of this work: Identifying the conditions under which the LCMNB algorithm holds with respect to the SNB algorithm. But first we need to describe the estimation of p(ωi|xj = 0).

Estimation of p(ωi|xj = 0): In Our Approach

In regard to the case of xj = 0, we make use of Remark 1, Remark 2 and Eq. 13, which yield an estimator for p(ωi|xj = 0) as

p(ωi|xj=0)=Nωi(Nij+αi)N(Nj++i=1Cαi) (17)

Naive Bayes: scoring function from

For notational convenience let us denote Nij+αiNj++i=1Cαi in Eq. 15 and Nωi(Nij+αi)N(Nj++i=1Cαi) in Eq. 17 by ξij and νij, respectively.

Thus, p(ωi|xj = 1) and p(ωi|xj = 0) may be written more succinctly as p(ωi|xj)=ξijxjνij(1xj), which allows us to express Eq. 11 more compactly as

p(ωi|x)p(ωi)=Πjp(ωi|xj)pL(ωi)×Πjp(xj)p(x1,x2,....,xL)=Πjξijxjνij(1xj)pL(ωi)×Πjp(xj)p(x1,x2,....,xL) (18)

Now we come to the core of this work, under which conditions does the LCMNB algorithm hold with respect to the SNB algorithm? Before we answer this question, we deem it instructive and more insightful to map Eq. 18 monotonically to a discriminant function, a “scoring function” (so to speak).

To this end, taking the logarithm of Eq. 18 results in

Sωi(x)=lnp(ωi|x)p(ωi)=lnΠjξijxjνij(1xj)pL(ωi)×Πjp(xj)p(x1,x2,...,xL) (19)
=jxjlnξij+j(1xj)lnνijL×lnp(ωi)+jlnp(xj)lnp(x1,x2,...,xL) (20)

Self–evidently, the term jlnp(xj)lnp(x1,x2,...,xL) is common to all classes and therefore does not play any role in classifying a given new compound. In other words, for practical classification purposes we are only interested in class dependent terms, i.e.,

Dωi(x)=jxjlnξijlnp(ωi)+j(1xj)lnνij(L1)×lnp(ωi) (21)

where Sωi(x)=Dωi(x)+jlnp(xj)lnp(x1,x2,...,xL)

Conditions

In Xia et al.’s approach, the LCMNB algorithm, is none other than jxjlnξijlnp(ωi) in Eq. 21. This means that in Xia et al.’s scheme the contributions from the terms depending on xj = 0 for a given class, i.e.,

j(1xj)lnνij(L1)×lnp(ωi),i,i=1,2,..,C (22)

are discarded. To the best of our knowledge, neither in Xia et al. nor in any other paper on the LCMNB approach has it been demonstrated that (i) the contribution of Eq. 22 is zero, i.e.,

j(1xj)lnνij(L1)×lnp(ωi)=0,i,i=1,2,..,C (23)

equally, in these papers, it has not been shown that (ii)

|jxjlnξijlnp(ωi)|>>|j(1xj)lnνij(L1)×lnp(ωi)|,i,i=1,2,..,C (24)

nor has it been established that (iii)

j(1xj)lnνij(L1)×lnp(ωi)=constant,i,i=1,2,..,C (25)

Thus unless one (or more) of the above – (i), (ii) and (iii) – is (are) met, the assumption on which the Modified Naive Bayesian algorithm is based is questionable and therefore its practitioners should pay attention to this discrepancy; clearly it is not justifiable to discard from the onset the contribution of j(1xj)lnνij(L1)×lnp(ωi) simply because features x j are absent, i.e. xj = 0.

For completeness, we consider also the case of the highly popular class prior distribution, p(ωi)=1C, i.e. p(ω1) = p(ω2) = ... = p(ωC). We hasten to add that this option was not included in the LCMNB scheme. At any rate, by simply repeating the arguments in the preceding sections, it is straightforward to show that one ends up with Eq. 21. In this scenario, though, L × lnp(ωi) is common to all classes and therefore does not play a role in classifying a new compound, i.e., Dωi(x) reduces to

Dωi(x)=jxjlnξij+j(1xj)lnνij (26)

Conclusions

Starting from a standard Naive Bayes (SNB) algorithm, we have derived mathematically the relationship between Xia et al.’s ingenious, but heuristic algorithm, and the standard Naive Bayes approach. We also describe the conditions on which Xia et al.’s crucial assumption – contributions from absent feature can be discarded – holds. It is our hope that, with this new insight, cheminformaticians may now be able to efficiently use the Modified version of the standard Naive Bayes algorithm, as proposed by Xia et al., and subsequently by Nidhi et al. and Nigsch et al.

Appendix

Appendix A: Estimator of p(xj|ωi)

Here we give for completeness the proof that a priori Beta distribution leads to Eqs. 12 and 13 in the text.

For bookkeeping:

ωi: class label indexed by i, i = 1,2,...,C.

C: Number of classes.

Nωi: Number of samples in class ωi.

Nij: Number of samples in class ωi with feature xj = 1, j = 1,2,...,L.

L: Number of features.

We state from the onset, in the following derivation we follow closely the descriptions given in ref. [10]. We also note, for clarity’s sake, in the following analyses we abuse notation and use xjk for both the random variable and its realization.

In this work, x ∈ {0,1}L, i.e. xj ∈ {0,1} and suppose that xj are independent Bernoulli random variables (and this is in fact the assumption made in the Naive Bayesian approach). Thus, in the Naive Bayesian setting p(x|ωi) can be given as

p(x|ωi)=Πj=1LBer(xj|μij)=Πj=1Lμijxj(1μij)1xj (27)

where μij is an estimate for the conditional probability that feature j occurs in class ωi, and is what we are trying to estimate given a set of compounds assumed to belong to class ωi. (In our context, μij is an estimator for p(xj|ωi), where p(xj|ωi)is as defined in the text.)

To estimate μij in a Bayesian framework, we first view μij as a random variable, then choose an “appropriate” prior and likelihood for the random variable μij.

Let us suppose that our a priori knowledge about the random variable μij indicates that μij is described by a Beta distribution, i.e.,

π(μij)=1B(αi,βi)μijαi1(1μij)βi1,0μij1,αi,βi>0,i=1,2,...C (28)

where B(αi,βi) ensures that the Beta distribution is normalised

Using the Bayes’ theorem, then the posterior probability for μij on the training data can be given by

π(μij|xj1,xj2,...,xjNωi)=f(xj1,xj2,...,xjNωi|μij)π(μij)01f(xj1,xj2,...,xjNωi|μij)π(μij)dμij (29)

where f(xj1,xj2,...,xjNωi|μij)refers to the likelihood, and xj1,xj2,... and xjNωi denote the jth feature of the Nωi samples/compounds from class ωi. As the samples are assumed independent, then f(xj1,xj2,...,xjNωi|μij) becomes Πk=1Nωif(xjk|μij)=Πk=1Nωiμijxjk(1μij)1xjk, i.e.

Πk=1Nωif(xjk|μij)=μijk=1mxjk(1μij)Nωik=1Nωixjk (30)

Thus, the posterior π(μij|xj1,xj2,...,xjM) in Eq. 29 modifies to

π(μij|xj1,xj2,...,xjNωi)=μijk=1Nωixjk(1μij)Nωik=1Nωixjkπ(μij)01μijk=1Nωixjk(1μij)Nωik=1Nωixjkπ(μij)dμij (31)

i.e.,

π(μij|xj1,xj2,...,xjNωi)μijk=1Nωixjk(1μij)Nωik=1Nωixjkπ(μij) (32)
=μijk=1Nωixjk(1μij)Nωik=1Nωixjk×μijαi1(1μij)βi1 (33)
=μijNij+αi1(1μij)NωiNij+βi1 (34)

Clearly, in Eq. 34, the posterior density for μij given the samples xj1,xj2,...,xjNωi has the same form as the prior for μij[11], i.e.,

π(μij|xj1,xj2,...,xjNωi)=1B(Nij+αi,NωiNij+βi)μijNij+αi1(1μij)NωiNij+βi1 (35)

which is none other than another Beta distribution. This means that the Bayes estimator of μij, which is the estimate we are interested in, is the mean of the posterior distribution obtained [11]:

E[μij|xj1,xj2,...,xjNωi]=Nij+αiNωi+αi+βi (36)

In other words,

p(xj|ωi)=Nij+αiNωi+αi+βi (37)

QED.

An accessible description of the derivation of Eq. 37 can be found in ref. [10].

Competing interests

The authors declare that they have no competing interests.

Authors’ contributions

HYM conceived the idea that constitutes the nub of the presented work. This author also carried out the bulk of the mathematical derivations. RCG contributed to the Bayesian aspect of the work. JBOM conceptually contributed to the derivation given in Appendix A. The three authors participated in drafting the manuscript. All authors read and approved the final manuscript.

Contributor Information

Hamse Y Mussa, Email: hym21@cam.ac.uk.

John BO Mitchell, Email: jbom@st-andrews.ac.uk.

Robert C Glen, Email: rcg28@cam.ac.uk.

Acknowledgements

We are in debt to Dr Dave Rogers for his many useful comments on the original LCMNB approach, in particular for helping us understand more about the two–class LCMNB version.

Mussa and Glen would like to thank the Unilever Centre for Molecular Sciences Informatics for its support, whereas Mitchell would like to thank the Scottish Universities Life Sciences Alliance (SULSA).

References

  1. Murphy KP. Machine Learning: A Probabilistic Perspective. Cambridge, MA: MIT Press; 2012. [Google Scholar]
  2. Xia X, Maliski EG, Gallant P, Rogers D. Classification of kinase inhibitors using a Bayesian model. J Med Chem. 2004;47:4463–4470. doi: 10.1021/jm0303195. [DOI] [PubMed] [Google Scholar]
  3. Glick M, Davies JW, Jenkins JL. Nidhi. Prediction of biological targets for compounds using multiple-category Bayesian models trained on chemogenomics databases. J Chem Inf Model. 2006;46:1124–1133. doi: 10.1021/ci060003g. [DOI] [PubMed] [Google Scholar]
  4. Nigsch F, Bender A, Jenkins JL, Mitchell JBO. Ligand-target prediction using winnow and naive Bayesian algorithms and the implications of overall performance statistics. J Chem Inf Model. 2008;48:2313–2325. doi: 10.1021/ci800079x. [DOI] [PubMed] [Google Scholar]
  5. Rogers D, Brown RD, Hahn M. Using extended–connectivity fingerprints with Laplacian-modified Bayesian analysis in high–throughput screening follow–up. J Biomol Screen. 2005;10:682–686. doi: 10.1177/1087057105281365. [DOI] [PubMed] [Google Scholar]
  6. Townsend JA, Glen RC, Mussa HY. Note on naive Bayes based on binary descriptors in Cheminformatics. J Chem Inf Model. 2012;52:2494–2500. doi: 10.1021/ci200303m. [DOI] [PubMed] [Google Scholar]
  7. Duda RO, Hart PE. Pattern Classification and Scene Analysis. New York, NY: John Wiley & Sons, Ltd; 1973. [Google Scholar]
  8. Koch RK. Introduction to Bayesian Statistics. Berlin: Springer; 2007. [Google Scholar]
  9. Bishop CM. Pattern Recognition and Machine Learning. New York: Springer; 2006. [Google Scholar]
  10. Ross SM. Introduction to Probability and Statistics for Engineers and Scientist. New York: John Wiley & Sons; 1987. [Google Scholar]
  11. Davidson AC. Statistical Models (Cambridge Series in Statistical and Probabilistic Mathematics) Cambridge: Cambridge University Press; 2008. [Google Scholar]

Articles from Journal of Cheminformatics are provided here courtesy of BMC

RESOURCES