{"id":648,"date":"2019-01-08T11:13:13","date_gmt":"2019-01-08T11:13:13","guid":{"rendered":"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=648"},"modified":"2019-01-08T11:56:48","modified_gmt":"2019-01-08T11:56:48","slug":"naive-bayes-classification","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/chapter\/naive-bayes-classification\/","title":{"rendered":"Na\u00efve Bayes Classification"},"content":{"raw":"<div>\r\n\r\n&nbsp;\r\n\r\n<strong>Learning Objectives:<\/strong>\r\n\r\n&nbsp;\r\n\r\nThe learning objectives of this module are as follows:\r\n\r\n&nbsp;\r\n\r\n\u2022 To understand Probabilistic Classification\r\n\r\n&nbsp;\r\n\r\n\u2022 To explain Na\u00efve Bayes Classifier\r\n\r\n&nbsp;\r\n\r\n\u2022 To understand some applications of Na\u00efve Bayes Classifier\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>30.1 Classification problem<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Let us again look at the classification problem, a supervised learning problem. The training data consists of examples of the form (d,h(d)) where d is the data object to classify (inputs) and h(d) is the correct class information for d. The goal of classification is to find the class h(d<sub>new<\/sub>) of d<sub>new<\/sub>, an hitherto unseen data object (Figure 30.1).<\/p>\r\n<img class=\"aligncenter size-full wp-image-652\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-106.png\" alt=\"\" width=\"456\" height=\"225\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.1 Supervised Learning<\/strong><\/p>\r\n\r\n<\/div>\r\n<strong>\u00a0<\/strong>\r\n\r\n<strong style=\"text-align: initial;font-size: 1em\">30.1.1 Methods to Create Classifiers<\/strong>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nThere are three methods to establish a classifier as given below:\r\n\r\n&nbsp;\r\n\r\na)\u00a0<strong>Model a classification rule directly - <\/strong>Examples: k-NN, decision trees, perceptron, SVM\r\n\r\n&nbsp;\r\n\r\nb)\u00a0<strong>Model the probability of class memberships given input data - <\/strong>Example: perceptron with the cross-entropy cost\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">c)\u00a0<strong>Make a probabilistic model of data within each class - <\/strong>Examples:<strong> naive Bayes<\/strong>, model based classifiers Of these methods a) and b) are examples of discriminative classification and <em>c<\/em>) is an example of generative classification. Moreover <em>b<\/em>) and <em>c<\/em>) are both examples of probabilistic classification.<\/p>\r\n&nbsp;\r\n\r\n<strong>30.2 <\/strong><strong>Probabilistic Classification<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Generally, in classification the goal is to predict the value of a class c given the value of a input feature vector x. From a probabilistic perspective, the goal is to find the conditional distribution p(c|x).There are two types of probabilistic models of classification, the discriminative model and the generative model.<\/p>\r\n&nbsp;\r\n\r\n<strong>30.2.1 Discriminative model<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The most common approach to probabilistic classification is to represent the conditional distribution using a parametric model, and then to determine the parameters using a training set consisting of pairs &lt;xn, cn&gt; of input vectors along with their corresponding target output vectors. In other words discriminative classifiers model the posterior p(c|x) directly which can then be used to make predictions of c for new values of x (Figure 30.2). Here for example the classes can be C1=benign mole or C2 = cancer which can be modelled given the respective data points. This is known as a discriminative approach, since the conditional distribution discriminates directly between the different values of c.<\/p>\r\n&nbsp;\r\n\r\n<img class=\"aligncenter size-full wp-image-653\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-107.png\" alt=\"\" width=\"566\" height=\"210\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: center\"><strong>Figure 30.2 Discriminative Model<\/strong><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>30.2.2 Generative model<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The generative model is a model for randomly generating observable data values, typically given some hidden parameters. It specifies a joint probability distribution over observation and label sequences. Generative models are used for modelling data directly that is modelling observations drawn from a probability density function). This approach to probabilistic classification finds the joint distribution p(x, c), expressed for instance as a parametric model, and then subsequently use this joint distribution to evaluate the conditional p(c|x) in order to make predictions of c for new values of x by application of Bayes theorem. This is known as a generative approach since by sampling from the joint distribution it is possible to generate synthetic examples of the feature vector x (Figure 30.3). Here for the vector of random variables we learn the probability for each class c given the input. In practice, the generalization performance of generative models is often found to be poorer than that of discriminative models due to differences between the model and the true distribution of the data.<\/p>\r\n<img class=\"aligncenter size-full wp-image-654\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-108.png\" alt=\"\" width=\"590\" height=\"215\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.3 Generative Model<\/strong><\/p>\r\n&nbsp;\r\n\r\n<strong>30.3 Na\u00efve Bayes<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Na\u00efve Bayes is a type of generative model. Here we try to determine the conditional probability P(C|X) that is the probability of a class given a set or bag of features. This probability can be determined by finding the likelihood of the input features given the class and the prior probability of the class. Here the difficulty lies in learning the joint probability of the features given the class.<\/p>\r\n<img class=\"aligncenter size-full wp-image-655\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-109.png\" alt=\"\" width=\"566\" height=\"60\" \/>\r\n<p style=\"text-align: justify\">An important assumption that Na\u00efve Bayes method makes is that <strong>all input<\/strong> <strong>attributes are conditionally independent. <\/strong>In other words assume that the\u00a0<span style=\"font-size: 1em;text-align: initial\">joint probability can be found by finding the individual probability of each feature given the class (Figure 30.4).<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-656\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-110.png\" alt=\"\" width=\"540\" height=\"144\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.4 Na\u00efve Bayes Assumption<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">This is an important special, simplification of a Bayes optimal classifier, where the hypothesis is the classification and all attributes are conditionally independent given the class (Figure 30.5)<\/p>\r\n<img class=\"aligncenter size-full wp-image-657\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-111.png\" alt=\"\" width=\"487\" height=\"194\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.5 Independence of Attributes<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The setting for the Na\u00efve Bayes classifier is where a set of training examples is provided, and a new instance is presented, described by the tuple of attribute values <strong><em>(a<\/em><\/strong><strong><em>l<\/em><\/strong><strong><em>, a<\/em><\/strong><strong><em>2<\/em><\/strong> <strong><em>...a<\/em><\/strong><strong><em>n<\/em><\/strong><strong><em>).<\/em><\/strong> The job of the learner is to predict the target value (classification), for this new instance.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Na\u00efve Bayes is one of the most practical Bayes learning methods. The naive Bayes classifier applies to learning tasks where each instance <em>x<\/em> is described by a conjunction of attribute values and where the target function f (x) can take on any value from some finite set V. Na\u00efve Bayes method is generally used when there is a moderate or large training set available and when attributes that describe instances are conditionally independent given the classification. Some successful applications of Na\u00efve Bayes method are medical diagnosis and classifying text documents.<\/p>\r\n&nbsp;\r\n\r\n<strong>30.3 Na\u00efve Bayes Classifier: Assumptions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">As already discussed for the Na\u00efve Bayes classifier we need to determine two probabilities that is prior probability of the class and the likelihood of the data with respect to the class<em>.<\/em><\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<span style=\"text-align: initial;font-size: 1em\">The prior probability of the class <\/span><strong style=\"text-align: initial;font-size: 1em\"><em>P<\/em>(<em>c<\/em><\/strong><strong style=\"text-align: initial;font-size: 1em\"><em>j<\/em><\/strong><strong style=\"text-align: initial;font-size: 1em\">) c<\/strong><span style=\"text-align: initial;font-size: 1em\">an be estimated from the frequency of classes in the training examples.<\/span>\r\n<div>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">However the likelihood or the joint probability of the features of the input data given the class <strong><em>P<\/em>(<em>x<\/em><\/strong><strong><em>1<\/em><\/strong><strong><em>,x<\/em><\/strong><strong><em>2<\/em><\/strong><strong><em>,\u2026,x<\/em><\/strong><strong><em>n<\/em><\/strong><strong><em>|c<\/em><\/strong><strong><em>j<\/em><\/strong><strong>)<\/strong> is of the order of O(<em>|X|<\/em><em>n<\/em>\u2022<em>|C|<\/em>) and can only be estimated if a very, very large number of training examples was available. This is where the naivety of Na\u00efve Bayes method comes into the picture that is the <strong>conditional independence assumption <\/strong>where we assume that the probability of observing the conjunction of attributes is equal to the product of the individual probabilities.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Let us first formulate Bayesian Learning. Let each instance <em>x<\/em> of a training set <em>D<\/em> be a conjunction of <em>n<\/em> attribute values <em>&lt;a<\/em><em>1<\/em><em>,a<\/em><em>2<\/em><em>,..,a<\/em><em>n<\/em><em>&gt;<\/em> and let <em>f(x),<\/em> the target function, be such that <em>f(x)<\/em> <em>\u00ce<\/em> <em>V<\/em>, a finite set. According to the Bayesian approach using Maximum A Posteriori (MAP) we can specify this as follows:<\/p>\r\n<img class=\"aligncenter size-full wp-image-658\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-112.png\" alt=\"\" width=\"476\" height=\"119\" \/>\r\n<p style=\"text-align: justify\">Here we try to find a value <strong><em>v<\/em><\/strong><strong><em>j<\/em><\/strong> that maximizes the probability given the attribute values. Applying Bayes Theorem this is finding the <strong><em>v<\/em><\/strong><strong><em>j<\/em><\/strong> that maximizes the product of the likelihood <strong><em>P(a<\/em><\/strong><strong><em>1<\/em><\/strong><strong><em>,a<\/em><\/strong><strong><em>2<\/em><\/strong><strong><em>,..,a<\/em><\/strong><strong><em>n<\/em><\/strong><strong><em>|v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>)<\/em><\/strong> and the prior probability <strong><em>P(v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>).<\/em><\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Now according to <strong>Na\u00efve Bayesian Approach, w<\/strong>e assume that the attribute values are conditionally independent so that <strong><em>P(a<\/em><\/strong><strong><em>1<\/em><\/strong><strong><em>,a<\/em><\/strong><strong><em>2<\/em><\/strong><strong><em>,..,a<\/em><\/strong><strong><em>n<\/em><\/strong><strong><em>|v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>) =<\/em><\/strong><strong><em>\u00d5<\/em><\/strong><strong><em>i<\/em><\/strong> <strong><em>P(a<\/em><\/strong><strong><em>1<\/em><\/strong><strong><em>|v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>)<\/em><\/strong>. This means that too large a data set is not required.<\/p>\r\n&nbsp;\r\n\r\nTherefore\u00a0 <em style=\"font-weight: bold\">Na\u00efve Bayes Classifier:<\/em>\u00a0<strong><em>v<\/em><\/strong><strong><em>NB<\/em><\/strong><strong><em> = argmax<\/em><\/strong><strong><em>vj<\/em><\/strong>\u00ce <strong><em>V<\/em><\/strong><strong><em> P(v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>) <\/em><\/strong>\u00d5<strong><em>i<\/em><\/strong><strong><em> P(a<\/em><\/strong><strong><em>i<\/em><\/strong><strong><em>|v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>)\u00a0<\/em><\/strong>Na\u00efve assumption of attribute independence for a set of k features is as given below:\r\n\r\n&nbsp;\r\n\r\nP(x1,\u2026,xk|C) = P(x1|C)\u00b7\u2026\u00b7P(xk|C)\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Now if the If i-th attribute is categorical then P(xi|C) is estimated as the relative freq of samples having value xi. However if the i-th attribute is continuous then P(xi|C) is estimated through a Gaussian density function. It is computationally easy in both cases.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">30.5 Na\u00efve Bayes Algorithm<\/strong><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\nNa\u00efve Bayes Algorithm (considering discrete input attributes) has two phases\r\n\r\n&nbsp;\r\n\r\n<strong>1.\u00a0 <\/strong><strong>Learning Phase<\/strong>: Given a training set<strong> S<\/strong>,\r\n\r\n<img class=\"aligncenter size-full wp-image-659\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-113.png\" alt=\"\" width=\"608\" height=\"176\" \/>\r\n\r\n&nbsp;\r\n\r\n2. <strong>Test Phase<\/strong>: Given an unknown instance Xj, Nj X L Look up tables to assign the label <em>c*<\/em> to <strong>X\u2019<\/strong> if X\u2019 = (a1\u2019, a2\u2019, \u2026\u2026an\u2019) Classification is easy, just multiply probabilities\r\n\r\n<img class=\"aligncenter size-full wp-image-660\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-114.png\" alt=\"\" width=\"596\" height=\"61\" \/>\r\n\r\n<strong>Naive Bayes Classifier<\/strong>\r\n\r\n&nbsp;\r\n\r\nIn general we assume that target function is <em>f: X<\/em> <em>\u00e8<\/em> <em>V<\/em>, where each instance <em>x<\/em> is described by attributes <em>a<\/em><em>1<\/em><em>, a<\/em><em>2<\/em> <em>.. a<\/em><em>n<\/em>\r\n\r\n<img class=\"aligncenter size-full wp-image-661\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-115.png\" alt=\"\" width=\"602\" height=\"412\" \/>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-662\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-116.png\" alt=\"\" width=\"605\" height=\"418\" \/><img class=\"aligncenter size-full wp-image-663\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-117.png\" alt=\"\" width=\"583\" height=\"440\" \/>\r\n\r\n<strong>30.6 Characteristics of Na\u00efve Bayes<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Therefore Na\u00efve Bayes classifier only requires the estimation of the prior probabilities <em>P(C<\/em><sub><em>K<\/em><\/sub><em>)<\/em> (where k is the given number of classes), and <em>p<\/em> (where p is the number of attributes) conditional probabilities for each class. We will be able to answer full set of queries across classes and features. Empirical evidence shows that Na\u00efve Bayes\u00a0<span style=\"font-size: 1em;text-align: initial\">classifiers work remarkable well. It has been that the use of a more complex full Bayes (belief) network provides only limited improvements in classification performance.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>30.7 Example 1 \u2013 Playing Tennis<\/strong>\r\n\r\n&nbsp;\r\n\r\nGiven a training set (Figure 30.6), we can compute probabilities from the data.\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong>Training Phase: <\/strong>First we compute the probabilities of Playing tennis (positive) and not Playing Tennis (negative) as P(p) and P(n) respectively (Figure 30.7).<\/p>\r\n<img class=\"aligncenter size-full wp-image-664\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-118.png\" alt=\"\" width=\"180\" height=\"59\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.7 Probability of Playing tennis and not Playing Tennis<\/strong><\/p>\r\n&nbsp;\r\n\r\nProbabilities of each of the attributes is then calculated as given below:\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We need to estimate P(xi|C) where xi is each value for each attribute given C which is either positive (p) or negative (n) class for Play Tennis. For example consider the attribute Outlook has value sunny for 2 of the 9 positive samples (2\/9) and for 3 of the 5 negative samples (3\/5). We calculate such probabilities for every other attribute value for attribute Outlook and similarly for each value of each of the other attributes Temperature, Humidity and Windy (Figure 30.8)<\/p>\r\n<img class=\"aligncenter size-full wp-image-665\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-119.png\" alt=\"\" width=\"510\" height=\"383\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.8 Conditional Probabilities of each Attribute<\/strong><\/p>\r\n\r\n<\/div>\r\n<p style=\"text-align: justify\"><strong>\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">Test Phase<\/strong><span style=\"text-align: initial;font-size: 1em\">: Given a new instance<\/span><strong style=\"text-align: initial;font-size: 1em\"> x\u2019 <\/strong><span style=\"text-align: initial;font-size: 1em\">of variable values, we need to calculate the probability of either Playing Tennis or not Playing Tennis. Now assume we are given the values of the four attributes as shown below:<\/span><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">x\u2019=(Outlook=<em>Sunny,<\/em> Temperature=<em>Cool,<\/em> Humidity<em>=High,<\/em> Wind=<em>Strong<\/em>)<\/strong><\/p>\r\n\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-666\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-120.png\" alt=\"\" width=\"579\" height=\"278\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.9 Calculating whether Tennis will be played given the new instance<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Here we consider the probability of Outlook being Sunny and look up the probability of Play Tennis and not Play tennis. Similarly we look up the probabilities for Temperature =Cool, Humidity = High and Wind = Strong. Now we can calculate the probability of Playing tennis and not Playing Tennis given the new instance <strong>x\u2019<\/strong> by finding the product of each of the probabilities obtained for the value of each variable. Now we find that P(Yes\/ x\u2019) = 0.0053 and P(No\/ x\u2019) = 0.0206. Since P(No\/ x\u2019) is greater we can conclude that the new instance <strong>x\u2019 <\/strong>will be labelled as No.<\/p>\r\n&nbsp;\r\n\r\n<strong>30.8 Example 2 \u2013 Text Classification<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">We learn from examples which articles are of interest. The attributes in this case are the words. Since we are talking about the Na\u00efve Bayes model, this just means that we have a random sequence model within each class. It has been found that NB classifiers are one of the most effective classifiers for this task.<\/p>\r\n&nbsp;\r\n\r\n<strong>30.8.1 Definition of Text Classification<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">First let us define the Text Classification problem. Here a document d is a data point in multi-dimensional space X, whose dimension is based on the number of unique words in the corpus. C is the set of categories we want the documents to be classified under. D is the training set of labelled documents &lt;d,c&gt;. The learning algorithm needs to find a mapping g that X \u00ae C (Figure 30.10).<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-667\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-121.png\" alt=\"\" width=\"519\" height=\"226\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.10 Definition of Text Classification <\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong>30.8.2 Uses of Text Classification<\/strong><\/p>\r\n&nbsp;\r\n\r\nText classification is the task of classifying text documents to multiple classes.\r\n\r\n&nbsp;\r\n\r\nThis has many applications as listed below:\r\n\r\n&nbsp;\r\n\r\n\u2013\u00a0 Is this mail spam?\r\n\r\n\u2013\u00a0 Is this article from comp.ai or misc.piano?\r\n\r\n\u2013\u00a0 Is this article likely to be relevant to user X?\r\n\r\n\u2013 Is this page likely to lead me to pages relevant to my topic? (as in topic-specific crawling), etc.\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>30.8.3 Na\u00efve Bayes Classifier and Text Classification<\/strong>\r\n\r\n&nbsp;\r\n\r\n<strong>30.8.3.1 Document Representation<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Na\u00efve Bayes Classifier has been applied widely for text classification tasks. The question to be answered is how to represent text documents as feature vectors? The vector space representation is one where each document is represented by a n dimensional vector where n is the number of unique words (after removing all stop words) of all the documents in the document corpus (the collection unique words is called vocabulary).There are many vector space variants. The vector space model that is widely used is the one where each document is represented in each dimension by the frequency of occurrences of the words. One variant of the vector representation is the binary version each dimension is 1 if the word is present in the document, 0 otherwise. A problem with vector space representation is that the vectors are likely to be as large as the size of the vocabulary. Then \u201cfeature selection\u201d techniques are used to select only a subset of words as features. One simple feature selection method is to limit the vocabulary by having words with frequency of occurrence that are above a threshold. In another variation of the vector space model we have the unigram model where the document is represented as a vector of positions with values being the words.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">30.8.3.2 Na\u00efve Bayes Algorithm \u2013Testing Phase<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">During the testing phase, given a test document <\/span><em style=\"text-align: initial;font-size: 1em\">X where n is<\/em><span style=\"text-align: initial;font-size: 1em\"> the number of word occurrences in <\/span><em style=\"text-align: initial;font-size: 1em\">X, we need to r<\/em><span style=\"text-align: initial;font-size: 1em\">eturn the category of the document. Here we find the category C using Maximum Likelihood that is the C that gives maximum probability with product of likelihood of n attributes given Ci and the prior probability of Ci. Here we assume that <\/span><em style=\"text-align: initial;font-size: 1em\">a<\/em><em style=\"text-align: initial;font-size: 1em\">j<\/em><span style=\"text-align: initial;font-size: 1em\"> is the word occurring at the the <\/span><em style=\"text-align: initial;font-size: 1em\">j<\/em><span style=\"text-align: initial;font-size: 1em\">th position in X. The probabilities of each of the attributes is assumed to be independent according to the Na\u00efve Bayes assumption.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-668\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-122.png\" alt=\"\" width=\"429\" height=\"89\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>30.8.3.3 Text Na\u00efve Bayes Algorithm \u2013 Training Phase<\/strong>\r\n\r\n&nbsp;\r\n\r\n<img class=\"aligncenter size-full wp-image-669\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-123.png\" alt=\"\" width=\"568\" height=\"254\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>30.9 Learning the Model<\/strong>\r\n\r\n<img class=\"aligncenter size-full wp-image-670\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-124.png\" alt=\"\" width=\"479\" height=\"166\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.11 Na\u00efve Bayes Model<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Let us assume that the Na\u00efve Bayes Model is represented as in Figure 30.11 where C is the class which is dependent on 6 attributes. The common practice used to find the maximum likelihood is to simply use the frequencies in the data. The two terms of Maximum Likelihood, prior probability and likelihood are\u00a0<span style=\"font-size: 1em;text-align: initial\">calculated as given below. We explain with document classification as example. The prior probability P(cj) of a class cj is calculated as the number of documents in the labelled corpus with category C=c<sub>j<\/sub> divided by the total number of documents. The likelihood of the each attribute or feature (word) xi given class c<sub>j<\/sub> is calculated as the number of documents of class cj having that attribute divided by the total number of documents of class cj. We find the posterior probability for each class in this way.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-671\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-125.png\" alt=\"\" width=\"479\" height=\"166\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.12 Calculating Prior Probability and Likelihood<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">In order to reemphasize the na\u00efve Bayes assumption, we use the example of classification of Flu given the 5 symptoms runnynose, sinus, cough, fever, muscle-ache (Figure 30.13). We do not find the probability of all symptoms occurring together but assume that the symptoms are independent and hence calculate the likelihood of each symptom given the class independently.<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-672\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-126.png\" alt=\"\" width=\"586\" height=\"366\" \/>\r\n<p style=\"text-align: justify\">Now the issue is what if we have seen no training cases where patient had no flu and muscle aches? In other words certain cases are zero because these cases not available in training set. Zero probabilities cannot be conditioned away, no matter the other evidence therefore we need to do some method of smoothing. We will explain this in the next section.<\/p>\r\n&nbsp;\r\n\r\n<strong>30.9.1 Naive Bayes - to Classify Text: Basic method<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Let us assume that the documents are represented by attributes that are text positions, where the values are words. This is as given below.<\/p>\r\n<img class=\"aligncenter size-full wp-image-673\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-127.png\" alt=\"\" width=\"586\" height=\"100\" \/>\r\n<p style=\"text-align: justify\">However there are too many possibilities. Now let us assume that the classification is <em>independent<\/em> of the positions of the words, now we need to use some parameters for each position and hence we come to what is called the \u201cBag of words\u201d model.<\/p>\r\n&nbsp;\r\n\r\n<strong>30.10 Example 3 \u2013Text Classification<\/strong>\r\n\r\n&nbsp;\r\n\r\nLet us take a toy example of text classification to explain Na\u00efve Bayes method. Let us assume we are given N=4 documents which are classified into two classes: \u201cChina\u201d, \u201cnot China\u201d. We are also know the vocabulary V = {Beijing, Chinese, Japan, Macao, Tokyo}. We need to classify the test document given.\r\n\r\n<img class=\"aligncenter size-full wp-image-674\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-128.png\" alt=\"\" width=\"598\" height=\"184\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.14 Example for Text Classification<\/strong><\/p>\r\n&nbsp;\r\n\r\nThe prior probability of class China and not China is given below:\r\n\r\n<img class=\"aligncenter size-full wp-image-675\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-129.png\" alt=\"\" width=\"445\" height=\"74\" \/>\r\n<p style=\"text-align: justify\">We need nonzero probabilities for all words, even for words that don't exist. So we just count every word one time more than it actually occurs ( a way of\u00a0<span style=\"font-size: 1em;text-align: initial\">smoothing). Since we are only concerned with relative probabilities, this inaccuracy should be of no concern. Therefore the way to calculate likelihood for the example is as follows (Figure 30.15):<\/span><\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<img class=\"aligncenter size-full wp-image-677\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-131.png\" alt=\"\" width=\"356\" height=\"141\" \/>\r\n<div>\r\n<p style=\"text-align: center\"><strong>Figure 30.15 Calculating Likelihood<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Now we need to carry out estimation to find the likelihood and use this to do the classification of the test document. We find the likelihood of each word (Chinese, Tokyo, Japan) in the test document for class Chinese and class not Chinese. Then we find the posterior probability of class Chinese and class not Chinese as given in Figure 30.16. We find that the probability for Class Chinese is higher and so that is the class of the test document.<\/p>\r\n<img class=\"aligncenter size-full wp-image-678\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-132.png\" alt=\"\" width=\"581\" height=\"174\" \/>\r\n<p style=\"text-align: center\"><strong>Figure 30.16 Estimation and Classification for the Example<\/strong><\/p>\r\n&nbsp;\r\n\r\n<strong>30.11 Na\u00efve Bayes Classifier - Comments<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The foremost reason for the wide use of Na\u00efve Bayes classifier is that it is easy to implement. The major advantage of Na\u00efve Bayes classifier is that it has good learning speed as well as classification speed. It has modest space storage requirements. In addition incrementality is supported. Recommendations can re-done as more attribute values of the new item become known. Another advantage is that it seems to work very well in many scenarios. Na\u00efve Bayes Classifier has much wider range of applicability than previously thought, this despite using the independence assumption.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">However classification accuracy is different from probability estimate accuracy. We make the assumption of class conditional independence and therefore there is loss of accuracy because practically, dependencies exist among variables. As an example in hospitals: we can have patients who have profiles\u00a0<span style=\"font-size: 1em;text-align: initial\">based on variables such as age, family history etc , who are associated with symptoms: such as fever, cough etc., and can have diseases such as lung cancer, diabetes etc and some of these variables are not independent. Dependencies among these variables cannot be modeled by Na\u00efve Bayesian Classifier, We will tackle these dependencies later using Bayesian Belief Networks.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>30.12 Issues Relevant to Na\u00efve Bayes<\/strong>\r\n\r\n&nbsp;\r\n\r\n1.\u00a0 <strong>Violation of Independence Assumption<\/strong>\r\n\r\n&nbsp;\r\n\r\nFor many real world tasks, events are correlated, but nevertheless, na\u00efve Bayes works surprisingly well anyway.\r\n\r\n<img class=\"aligncenter size-full wp-image-679\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-133.png\" alt=\"\" width=\"401\" height=\"52\" \/>\r\n\r\n&nbsp;\r\n\r\n2.\u00a0 <strong>Zero conditional probability Problem<\/strong>\r\n\r\n&nbsp;\r\n\r\nSuch problem exists when no example contains the attribute value\r\n\r\n<img class=\"aligncenter size-full wp-image-680\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-134.png\" alt=\"\" width=\"557\" height=\"148\" \/>\r\n<p style=\"text-align: justify\">during test. One solution to the issue is to estimate conditional probabilities with virtual examples. We have estimated probabilities by the fraction of times the event is observed to <em>n<\/em><em>c<\/em> occur over the total number of opportunities <em>n. However<\/em> this provides poor estimates when <em>n<\/em><em>c<\/em> is very small. What happens if none of the training instances with target value <em>v<\/em><em>j<\/em> have attribute value <em>a<\/em><em>i<\/em>? In other words <em>n<\/em><em>c<\/em> is 0.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">When <em>n<\/em><em>c<\/em> is very small we calculate likelihood as follows :<\/p>\r\n<img class=\"aligncenter size-full wp-image-681\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-135.png\" alt=\"\" width=\"293\" height=\"77\" \/>\r\n<p style=\"text-align: justify\"><em>Here n <\/em>is number of training examples for which<em> v=v<\/em><em>j<\/em><em> , n<\/em><em>c<\/em> number of examples for which <em>v=v<\/em><em>j<\/em> and <em>a=a<\/em><em>i,<\/em> <em>p<\/em> is <strong>prior<\/strong> estimate and <em>m<\/em> is weight given to prior (i.e. number of ``virtual'' examples) .<\/p>\r\n\r\n<\/div>\r\n<img class=\"aligncenter size-full wp-image-682\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-136.png\" alt=\"\" width=\"403\" height=\"67\" \/>\r\n\r\n<strong>Summary<\/strong>\r\n<ul>\r\n \t<li>Explained the concept of Probabilistic Classification<\/li>\r\n \t<li>Described Na\u00efve Bayes Classifier<\/li>\r\n \t<li>Discussed some applications of Na\u00efve Bayes Classifier<\/li>\r\n<\/ul>\r\n&nbsp;\r\n\r\n<strong>Web Links<\/strong>\r\n<ul>\r\n \t<li>studentnet.cs.manchester.ac.uk\/ugt\/COMP24111\/...\/Naive-Bayes.ppt<\/li>\r\n \t<li>web.cecs.pdx.edu\/...\/2015BayesTrees...\/2014_0095_Example%20of%20<\/li>\r\n \t<li>https:\/\/cse.sc.edu\/~rose\/587\/PPT\/NaiveBayes.ppt<\/li>\r\n \t<li>www.cs.unc.edu\/~lazebnik\/spring09\/lec20_generative.ppt<\/li>\r\n \t<li>cis-linux1.temple.edu\/~latecki\/Courses\/RobotFall08\/...\/bayesNaive.ppt<\/li>\r\n \t<li>www.cs.bu.edu\/fac\/gkollios\/ada01\/LectNotes\/Bayesian.ppt<\/li>\r\n<\/ul>\r\n&nbsp;\r\n\r\n<strong>Supporting &amp; Reference Materials<\/strong>\r\n<ul>\r\n \t<li>Tom <a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Mitchell&amp;search-alias=stripbooks\">Mitchell, <\/a>\u201cMachine Learning\u201d,McGraw-Hill Education, 1997<\/li>\r\n \t<li><a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Alpaydin+Ethem&amp;search-alias=stripbooks\">AlpaydinEthem, <\/a>\u201cIntroduction to Machine Learning\u201d, The MIT Press; third edition, 2014<\/li>\r\n \t<li>Christopher M. <a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Bishop&amp;search-alias=stripbooks\">Bishop, <\/a>\u201cPattern Recognition and Machine Learning\u201d,Springer, 2013 <a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Peter+Harrington&amp;search-alias=stripbooks\">Peter Harrington, <\/a>\u201cMachine Learning In Action\u201d, Manning Publications, 2012<\/li>\r\n \t<li><a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Peter+Flach&amp;search-alias=stripbooks\">Peter Flach, <\/a>\u201cMachine Learning: The Art and Science of Algorithms that Make Sense of Data\u201d,Cambridge University Press, 2012<\/li>\r\n \t<li><a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Stephen+Marsland&amp;search-alias=stripbooks\">Stephen Marsland, <\/a>\u201cMachine Learning: An Algorithmic Perspective\u201d, Chapman and Hall\/CRC; 2 edition, 2014<\/li>\r\n \t<li>S. Abu-Mostafa, M. Magdon-Ismail, and H.-T. Lin, \u201cLearning from Data\u201d, AMLBook, 2012.<\/li>\r\n<\/ul>","rendered":"<div>\n<p>&nbsp;<\/p>\n<p><strong>Learning Objectives:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The learning objectives of this module are as follows:<\/p>\n<p>&nbsp;<\/p>\n<p>\u2022 To understand Probabilistic Classification<\/p>\n<p>&nbsp;<\/p>\n<p>\u2022 To explain Na\u00efve Bayes Classifier<\/p>\n<p>&nbsp;<\/p>\n<p>\u2022 To understand some applications of Na\u00efve Bayes Classifier<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.1 Classification problem<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Let us again look at the classification problem, a supervised learning problem. The training data consists of examples of the form (d,h(d)) where d is the data object to classify (inputs) and h(d) is the correct class information for d. The goal of classification is to find the class h(d<sub>new<\/sub>) of d<sub>new<\/sub>, an hitherto unseen data object (Figure 30.1).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-652\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-106.png\" alt=\"\" width=\"456\" height=\"225\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-106.png 456w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-106-300x148.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-106-65x32.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-106-225x111.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-106-350x173.png 350w\" sizes=\"auto, (max-width: 456px) 100vw, 456px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.1 Supervised Learning<\/strong><\/p>\n<\/div>\n<p><strong>\u00a0<\/strong><\/p>\n<p><strong style=\"text-align: initial;font-size: 1em\">30.1.1 Methods to Create Classifiers<\/strong><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p>There are three methods to establish a classifier as given below:<\/p>\n<p>&nbsp;<\/p>\n<p>a)\u00a0<strong>Model a classification rule directly &#8211; <\/strong>Examples: k-NN, decision trees, perceptron, SVM<\/p>\n<p>&nbsp;<\/p>\n<p>b)\u00a0<strong>Model the probability of class memberships given input data &#8211; <\/strong>Example: perceptron with the cross-entropy cost<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">c)\u00a0<strong>Make a probabilistic model of data within each class &#8211; <\/strong>Examples:<strong> naive Bayes<\/strong>, model based classifiers Of these methods a) and b) are examples of discriminative classification and <em>c<\/em>) is an example of generative classification. Moreover <em>b<\/em>) and <em>c<\/em>) are both examples of probabilistic classification.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.2 <\/strong><strong>Probabilistic Classification<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Generally, in classification the goal is to predict the value of a class c given the value of a input feature vector x. From a probabilistic perspective, the goal is to find the conditional distribution p(c|x).There are two types of probabilistic models of classification, the discriminative model and the generative model.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.2.1 Discriminative model<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The most common approach to probabilistic classification is to represent the conditional distribution using a parametric model, and then to determine the parameters using a training set consisting of pairs &lt;xn, cn&gt; of input vectors along with their corresponding target output vectors. In other words discriminative classifiers model the posterior p(c|x) directly which can then be used to make predictions of c for new values of x (Figure 30.2). Here for example the classes can be C1=benign mole or C2 = cancer which can be modelled given the respective data points. This is known as a discriminative approach, since the conditional distribution discriminates directly between the different values of c.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-653\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-107.png\" alt=\"\" width=\"566\" height=\"210\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-107.png 566w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-107-300x111.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-107-65x24.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-107-225x83.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-107-350x130.png 350w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center\"><strong>Figure 30.2 Discriminative Model<\/strong><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>30.2.2 Generative model<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The generative model is a model for randomly generating observable data values, typically given some hidden parameters. It specifies a joint probability distribution over observation and label sequences. Generative models are used for modelling data directly that is modelling observations drawn from a probability density function). This approach to probabilistic classification finds the joint distribution p(x, c), expressed for instance as a parametric model, and then subsequently use this joint distribution to evaluate the conditional p(c|x) in order to make predictions of c for new values of x by application of Bayes theorem. This is known as a generative approach since by sampling from the joint distribution it is possible to generate synthetic examples of the feature vector x (Figure 30.3). Here for the vector of random variables we learn the probability for each class c given the input. In practice, the generalization performance of generative models is often found to be poorer than that of discriminative models due to differences between the model and the true distribution of the data.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-654\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-108.png\" alt=\"\" width=\"590\" height=\"215\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-108.png 590w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-108-300x109.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-108-65x24.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-108-225x82.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-108-350x128.png 350w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.3 Generative Model<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.3 Na\u00efve Bayes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Na\u00efve Bayes is a type of generative model. Here we try to determine the conditional probability P(C|X) that is the probability of a class given a set or bag of features. This probability can be determined by finding the likelihood of the input features given the class and the prior probability of the class. Here the difficulty lies in learning the joint probability of the features given the class.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-655\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-109.png\" alt=\"\" width=\"566\" height=\"60\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-109.png 566w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-109-300x32.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-109-65x7.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-109-225x24.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-109-350x37.png 350w\" sizes=\"auto, (max-width: 566px) 100vw, 566px\" \/><\/p>\n<p style=\"text-align: justify\">An important assumption that Na\u00efve Bayes method makes is that <strong>all input<\/strong> <strong>attributes are conditionally independent. <\/strong>In other words assume that the\u00a0<span style=\"font-size: 1em;text-align: initial\">joint probability can be found by finding the individual probability of each feature given the class (Figure 30.4).<\/span><\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-656\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-110.png\" alt=\"\" width=\"540\" height=\"144\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-110.png 540w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-110-300x80.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-110-65x17.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-110-225x60.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-110-350x93.png 350w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.4 Na\u00efve Bayes Assumption<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">This is an important special, simplification of a Bayes optimal classifier, where the hypothesis is the classification and all attributes are conditionally independent given the class (Figure 30.5)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-657\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-111.png\" alt=\"\" width=\"487\" height=\"194\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-111.png 487w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-111-300x120.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-111-65x26.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-111-225x90.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-111-350x139.png 350w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.5 Independence of Attributes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The setting for the Na\u00efve Bayes classifier is where a set of training examples is provided, and a new instance is presented, described by the tuple of attribute values <strong><em>(a<\/em><\/strong><strong><em>l<\/em><\/strong><strong><em>, a<\/em><\/strong><strong><em>2<\/em><\/strong> <strong><em>&#8230;a<\/em><\/strong><strong><em>n<\/em><\/strong><strong><em>).<\/em><\/strong> The job of the learner is to predict the target value (classification), for this new instance.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Na\u00efve Bayes is one of the most practical Bayes learning methods. The naive Bayes classifier applies to learning tasks where each instance <em>x<\/em> is described by a conjunction of attribute values and where the target function f (x) can take on any value from some finite set V. Na\u00efve Bayes method is generally used when there is a moderate or large training set available and when attributes that describe instances are conditionally independent given the classification. Some successful applications of Na\u00efve Bayes method are medical diagnosis and classifying text documents.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.3 Na\u00efve Bayes Classifier: Assumptions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">As already discussed for the Na\u00efve Bayes classifier we need to determine two probabilities that is prior probability of the class and the likelihood of the data with respect to the class<em>.<\/em><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"text-align: initial;font-size: 1em\">The prior probability of the class <\/span><strong style=\"text-align: initial;font-size: 1em\"><em>P<\/em>(<em>c<\/em><\/strong><strong style=\"text-align: initial;font-size: 1em\"><em>j<\/em><\/strong><strong style=\"text-align: initial;font-size: 1em\">) c<\/strong><span style=\"text-align: initial;font-size: 1em\">an be estimated from the frequency of classes in the training examples.<\/span><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">However the likelihood or the joint probability of the features of the input data given the class <strong><em>P<\/em>(<em>x<\/em><\/strong><strong><em>1<\/em><\/strong><strong><em>,x<\/em><\/strong><strong><em>2<\/em><\/strong><strong><em>,\u2026,x<\/em><\/strong><strong><em>n<\/em><\/strong><strong><em>|c<\/em><\/strong><strong><em>j<\/em><\/strong><strong>)<\/strong> is of the order of O(<em>|X|<\/em><em>n<\/em>\u2022<em>|C|<\/em>) and can only be estimated if a very, very large number of training examples was available. This is where the naivety of Na\u00efve Bayes method comes into the picture that is the <strong>conditional independence assumption <\/strong>where we assume that the probability of observing the conjunction of attributes is equal to the product of the individual probabilities.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Let us first formulate Bayesian Learning. Let each instance <em>x<\/em> of a training set <em>D<\/em> be a conjunction of <em>n<\/em> attribute values <em>&lt;a<\/em><em>1<\/em><em>,a<\/em><em>2<\/em><em>,..,a<\/em><em>n<\/em><em>&gt;<\/em> and let <em>f(x),<\/em> the target function, be such that <em>f(x)<\/em> <em>\u00ce<\/em> <em>V<\/em>, a finite set. According to the Bayesian approach using Maximum A Posteriori (MAP) we can specify this as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-658\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-112.png\" alt=\"\" width=\"476\" height=\"119\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-112.png 476w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-112-300x75.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-112-65x16.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-112-225x56.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-112-350x88.png 350w\" sizes=\"auto, (max-width: 476px) 100vw, 476px\" \/><\/p>\n<p style=\"text-align: justify\">Here we try to find a value <strong><em>v<\/em><\/strong><strong><em>j<\/em><\/strong> that maximizes the probability given the attribute values. Applying Bayes Theorem this is finding the <strong><em>v<\/em><\/strong><strong><em>j<\/em><\/strong> that maximizes the product of the likelihood <strong><em>P(a<\/em><\/strong><strong><em>1<\/em><\/strong><strong><em>,a<\/em><\/strong><strong><em>2<\/em><\/strong><strong><em>,..,a<\/em><\/strong><strong><em>n<\/em><\/strong><strong><em>|v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>)<\/em><\/strong> and the prior probability <strong><em>P(v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>).<\/em><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Now according to <strong>Na\u00efve Bayesian Approach, w<\/strong>e assume that the attribute values are conditionally independent so that <strong><em>P(a<\/em><\/strong><strong><em>1<\/em><\/strong><strong><em>,a<\/em><\/strong><strong><em>2<\/em><\/strong><strong><em>,..,a<\/em><\/strong><strong><em>n<\/em><\/strong><strong><em>|v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>) =<\/em><\/strong><strong><em>\u00d5<\/em><\/strong><strong><em>i<\/em><\/strong> <strong><em>P(a<\/em><\/strong><strong><em>1<\/em><\/strong><strong><em>|v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>)<\/em><\/strong>. This means that too large a data set is not required.<\/p>\n<p>&nbsp;<\/p>\n<p>Therefore\u00a0 <em style=\"font-weight: bold\">Na\u00efve Bayes Classifier:<\/em>\u00a0<strong><em>v<\/em><\/strong><strong><em>NB<\/em><\/strong><strong><em> = argmax<\/em><\/strong><strong><em>vj<\/em><\/strong>\u00ce <strong><em>V<\/em><\/strong><strong><em> P(v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>) <\/em><\/strong>\u00d5<strong><em>i<\/em><\/strong><strong><em> P(a<\/em><\/strong><strong><em>i<\/em><\/strong><strong><em>|v<\/em><\/strong><strong><em>j<\/em><\/strong><strong><em>)\u00a0<\/em><\/strong>Na\u00efve assumption of attribute independence for a set of k features is as given below:<\/p>\n<p>&nbsp;<\/p>\n<p>P(x1,\u2026,xk|C) = P(x1|C)\u00b7\u2026\u00b7P(xk|C)<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Now if the If i-th attribute is categorical then P(xi|C) is estimated as the relative freq of samples having value xi. However if the i-th attribute is continuous then P(xi|C) is estimated through a Gaussian density function. It is computationally easy in both cases.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">30.5 Na\u00efve Bayes Algorithm<\/strong><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p>Na\u00efve Bayes Algorithm (considering discrete input attributes) has two phases<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.\u00a0 <\/strong><strong>Learning Phase<\/strong>: Given a training set<strong> S<\/strong>,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-659\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-113.png\" alt=\"\" width=\"608\" height=\"176\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-113.png 608w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-113-300x87.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-113-65x19.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-113-225x65.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-113-350x101.png 350w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>2. <strong>Test Phase<\/strong>: Given an unknown instance Xj, Nj X L Look up tables to assign the label <em>c*<\/em> to <strong>X\u2019<\/strong> if X\u2019 = (a1\u2019, a2\u2019, \u2026\u2026an\u2019) Classification is easy, just multiply probabilities<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-660\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-114.png\" alt=\"\" width=\"596\" height=\"61\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-114.png 596w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-114-300x31.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-114-65x7.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-114-225x23.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-114-350x36.png 350w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/p>\n<p><strong>Naive Bayes Classifier<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>In general we assume that target function is <em>f: X<\/em> <em>\u00e8<\/em> <em>V<\/em>, where each instance <em>x<\/em> is described by attributes <em>a<\/em><em>1<\/em><em>, a<\/em><em>2<\/em> <em>.. a<\/em><em>n<\/em><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-661\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-115.png\" alt=\"\" width=\"602\" height=\"412\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-115.png 602w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-115-300x205.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-115-65x44.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-115-225x154.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-115-350x240.png 350w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-662\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-116.png\" alt=\"\" width=\"605\" height=\"418\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-116.png 605w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-116-300x207.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-116-65x45.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-116-225x155.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-116-350x242.png 350w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-663\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-117.png\" alt=\"\" width=\"583\" height=\"440\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-117.png 583w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-117-300x226.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-117-65x49.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-117-225x170.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-117-350x264.png 350w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/p>\n<p><strong>30.6 Characteristics of Na\u00efve Bayes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Therefore Na\u00efve Bayes classifier only requires the estimation of the prior probabilities <em>P(C<\/em><sub><em>K<\/em><\/sub><em>)<\/em> (where k is the given number of classes), and <em>p<\/em> (where p is the number of attributes) conditional probabilities for each class. We will be able to answer full set of queries across classes and features. Empirical evidence shows that Na\u00efve Bayes\u00a0<span style=\"font-size: 1em;text-align: initial\">classifiers work remarkable well. It has been that the use of a more complex full Bayes (belief) network provides only limited improvements in classification performance.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>30.7 Example 1 \u2013 Playing Tennis<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Given a training set (Figure 30.6), we can compute probabilities from the data.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong>Training Phase: <\/strong>First we compute the probabilities of Playing tennis (positive) and not Playing Tennis (negative) as P(p) and P(n) respectively (Figure 30.7).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-664\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-118.png\" alt=\"\" width=\"180\" height=\"59\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-118.png 180w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-118-65x21.png 65w\" sizes=\"auto, (max-width: 180px) 100vw, 180px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.7 Probability of Playing tennis and not Playing Tennis<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Probabilities of each of the attributes is then calculated as given below:<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We need to estimate P(xi|C) where xi is each value for each attribute given C which is either positive (p) or negative (n) class for Play Tennis. For example consider the attribute Outlook has value sunny for 2 of the 9 positive samples (2\/9) and for 3 of the 5 negative samples (3\/5). We calculate such probabilities for every other attribute value for attribute Outlook and similarly for each value of each of the other attributes Temperature, Humidity and Windy (Figure 30.8)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-665\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-119.png\" alt=\"\" width=\"510\" height=\"383\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-119.png 510w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-119-300x225.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-119-65x49.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-119-225x169.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-119-350x263.png 350w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.8 Conditional Probabilities of each Attribute<\/strong><\/p>\n<\/div>\n<p style=\"text-align: justify\"><strong>\u00a0<\/strong><strong style=\"text-align: initial;font-size: 1em\">Test Phase<\/strong><span style=\"text-align: initial;font-size: 1em\">: Given a new instance<\/span><strong style=\"text-align: initial;font-size: 1em\"> x\u2019 <\/strong><span style=\"text-align: initial;font-size: 1em\">of variable values, we need to calculate the probability of either Playing Tennis or not Playing Tennis. Now assume we are given the values of the four attributes as shown below:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">x\u2019=(Outlook=<em>Sunny,<\/em> Temperature=<em>Cool,<\/em> Humidity<em>=High,<\/em> Wind=<em>Strong<\/em>)<\/strong><\/p>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-666\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-120.png\" alt=\"\" width=\"579\" height=\"278\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-120.png 579w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-120-300x144.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-120-65x31.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-120-225x108.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-120-350x168.png 350w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.9 Calculating whether Tennis will be played given the new instance<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Here we consider the probability of Outlook being Sunny and look up the probability of Play Tennis and not Play tennis. Similarly we look up the probabilities for Temperature =Cool, Humidity = High and Wind = Strong. Now we can calculate the probability of Playing tennis and not Playing Tennis given the new instance <strong>x\u2019<\/strong> by finding the product of each of the probabilities obtained for the value of each variable. Now we find that P(Yes\/ x\u2019) = 0.0053 and P(No\/ x\u2019) = 0.0206. Since P(No\/ x\u2019) is greater we can conclude that the new instance <strong>x\u2019 <\/strong>will be labelled as No.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.8 Example 2 \u2013 Text Classification<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">We learn from examples which articles are of interest. The attributes in this case are the words. Since we are talking about the Na\u00efve Bayes model, this just means that we have a random sequence model within each class. It has been found that NB classifiers are one of the most effective classifiers for this task.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.8.1 Definition of Text Classification<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">First let us define the Text Classification problem. Here a document d is a data point in multi-dimensional space X, whose dimension is based on the number of unique words in the corpus. C is the set of categories we want the documents to be classified under. D is the training set of labelled documents &lt;d,c&gt;. The learning algorithm needs to find a mapping g that X \u00ae C (Figure 30.10).<\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-667\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-121.png\" alt=\"\" width=\"519\" height=\"226\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-121.png 519w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-121-300x131.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-121-65x28.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-121-225x98.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-121-350x152.png 350w\" sizes=\"auto, (max-width: 519px) 100vw, 519px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.10 Definition of Text Classification <\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong>30.8.2 Uses of Text Classification<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Text classification is the task of classifying text documents to multiple classes.<\/p>\n<p>&nbsp;<\/p>\n<p>This has many applications as listed below:<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0 Is this mail spam?<\/p>\n<p>\u2013\u00a0 Is this article from comp.ai or misc.piano?<\/p>\n<p>\u2013\u00a0 Is this article likely to be relevant to user X?<\/p>\n<p>\u2013 Is this page likely to lead me to pages relevant to my topic? (as in topic-specific crawling), etc.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.8.3 Na\u00efve Bayes Classifier and Text Classification<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.8.3.1 Document Representation<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Na\u00efve Bayes Classifier has been applied widely for text classification tasks. The question to be answered is how to represent text documents as feature vectors? The vector space representation is one where each document is represented by a n dimensional vector where n is the number of unique words (after removing all stop words) of all the documents in the document corpus (the collection unique words is called vocabulary).There are many vector space variants. The vector space model that is widely used is the one where each document is represented in each dimension by the frequency of occurrences of the words. One variant of the vector representation is the binary version each dimension is 1 if the word is present in the document, 0 otherwise. A problem with vector space representation is that the vectors are likely to be as large as the size of the vocabulary. Then \u201cfeature selection\u201d techniques are used to select only a subset of words as features. One simple feature selection method is to limit the vocabulary by having words with frequency of occurrence that are above a threshold. In another variation of the vector space model we have the unigram model where the document is represented as a vector of positions with values being the words.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong style=\"text-align: initial;font-size: 1em\">30.8.3.2 Na\u00efve Bayes Algorithm \u2013Testing Phase<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">During the testing phase, given a test document <\/span><em style=\"text-align: initial;font-size: 1em\">X where n is<\/em><span style=\"text-align: initial;font-size: 1em\"> the number of word occurrences in <\/span><em style=\"text-align: initial;font-size: 1em\">X, we need to r<\/em><span style=\"text-align: initial;font-size: 1em\">eturn the category of the document. Here we find the category C using Maximum Likelihood that is the C that gives maximum probability with product of likelihood of n attributes given Ci and the prior probability of Ci. Here we assume that <\/span><em style=\"text-align: initial;font-size: 1em\">a<\/em><em style=\"text-align: initial;font-size: 1em\">j<\/em><span style=\"text-align: initial;font-size: 1em\"> is the word occurring at the the <\/span><em style=\"text-align: initial;font-size: 1em\">j<\/em><span style=\"text-align: initial;font-size: 1em\">th position in X. The probabilities of each of the attributes is assumed to be independent according to the Na\u00efve Bayes assumption.<\/span><\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-668\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-122.png\" alt=\"\" width=\"429\" height=\"89\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-122.png 429w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-122-300x62.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-122-65x13.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-122-225x47.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-122-350x73.png 350w\" sizes=\"auto, (max-width: 429px) 100vw, 429px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.8.3.3 Text Na\u00efve Bayes Algorithm \u2013 Training Phase<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-669\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-123.png\" alt=\"\" width=\"568\" height=\"254\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-123.png 568w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-123-300x134.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-123-65x29.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-123-225x101.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-123-350x157.png 350w\" sizes=\"auto, (max-width: 568px) 100vw, 568px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.9 Learning the Model<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-670\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-124.png\" alt=\"\" width=\"479\" height=\"166\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-124.png 479w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-124-300x104.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-124-65x23.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-124-225x78.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-124-350x121.png 350w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.11 Na\u00efve Bayes Model<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Let us assume that the Na\u00efve Bayes Model is represented as in Figure 30.11 where C is the class which is dependent on 6 attributes. The common practice used to find the maximum likelihood is to simply use the frequencies in the data. The two terms of Maximum Likelihood, prior probability and likelihood are\u00a0<span style=\"font-size: 1em;text-align: initial\">calculated as given below. We explain with document classification as example. The prior probability P(cj) of a class cj is calculated as the number of documents in the labelled corpus with category C=c<sub>j<\/sub> divided by the total number of documents. The likelihood of the each attribute or feature (word) xi given class c<sub>j<\/sub> is calculated as the number of documents of class cj having that attribute divided by the total number of documents of class cj. We find the posterior probability for each class in this way.<\/span><\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-671\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-125.png\" alt=\"\" width=\"479\" height=\"166\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-125.png 479w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-125-300x104.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-125-65x23.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-125-225x78.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-125-350x121.png 350w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.12 Calculating Prior Probability and Likelihood<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In order to reemphasize the na\u00efve Bayes assumption, we use the example of classification of Flu given the 5 symptoms runnynose, sinus, cough, fever, muscle-ache (Figure 30.13). We do not find the probability of all symptoms occurring together but assume that the symptoms are independent and hence calculate the likelihood of each symptom given the class independently.<\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-672\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-126.png\" alt=\"\" width=\"586\" height=\"366\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-126.png 586w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-126-300x187.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-126-65x41.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-126-225x141.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-126-350x219.png 350w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/p>\n<p style=\"text-align: justify\">Now the issue is what if we have seen no training cases where patient had no flu and muscle aches? In other words certain cases are zero because these cases not available in training set. Zero probabilities cannot be conditioned away, no matter the other evidence therefore we need to do some method of smoothing. We will explain this in the next section.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.9.1 Naive Bayes &#8211; to Classify Text: Basic method<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Let us assume that the documents are represented by attributes that are text positions, where the values are words. This is as given below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-673\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-127.png\" alt=\"\" width=\"586\" height=\"100\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-127.png 586w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-127-300x51.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-127-65x11.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-127-225x38.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-127-350x60.png 350w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/p>\n<p style=\"text-align: justify\">However there are too many possibilities. Now let us assume that the classification is <em>independent<\/em> of the positions of the words, now we need to use some parameters for each position and hence we come to what is called the \u201cBag of words\u201d model.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.10 Example 3 \u2013Text Classification<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Let us take a toy example of text classification to explain Na\u00efve Bayes method. Let us assume we are given N=4 documents which are classified into two classes: \u201cChina\u201d, \u201cnot China\u201d. We are also know the vocabulary V = {Beijing, Chinese, Japan, Macao, Tokyo}. We need to classify the test document given.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-674\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-128.png\" alt=\"\" width=\"598\" height=\"184\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-128.png 598w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-128-300x92.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-128-65x20.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-128-225x69.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-128-350x108.png 350w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.14 Example for Text Classification<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>The prior probability of class China and not China is given below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-675\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-129.png\" alt=\"\" width=\"445\" height=\"74\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-129.png 445w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-129-300x50.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-129-65x11.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-129-225x37.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-129-350x58.png 350w\" sizes=\"auto, (max-width: 445px) 100vw, 445px\" \/><\/p>\n<p style=\"text-align: justify\">We need nonzero probabilities for all words, even for words that don&#8217;t exist. So we just count every word one time more than it actually occurs ( a way of\u00a0<span style=\"font-size: 1em;text-align: initial\">smoothing). Since we are only concerned with relative probabilities, this inaccuracy should be of no concern. Therefore the way to calculate likelihood for the example is as follows (Figure 30.15):<\/span><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-677\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-131.png\" alt=\"\" width=\"356\" height=\"141\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-131.png 356w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-131-300x119.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-131-65x26.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-131-225x89.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-131-350x139.png 350w\" sizes=\"auto, (max-width: 356px) 100vw, 356px\" \/><\/p>\n<div>\n<p style=\"text-align: center\"><strong>Figure 30.15 Calculating Likelihood<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Now we need to carry out estimation to find the likelihood and use this to do the classification of the test document. We find the likelihood of each word (Chinese, Tokyo, Japan) in the test document for class Chinese and class not Chinese. Then we find the posterior probability of class Chinese and class not Chinese as given in Figure 30.16. We find that the probability for Class Chinese is higher and so that is the class of the test document.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-678\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-132.png\" alt=\"\" width=\"581\" height=\"174\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-132.png 581w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-132-300x90.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-132-65x19.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-132-225x67.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-132-350x105.png 350w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/p>\n<p style=\"text-align: center\"><strong>Figure 30.16 Estimation and Classification for the Example<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>30.11 Na\u00efve Bayes Classifier &#8211; Comments<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The foremost reason for the wide use of Na\u00efve Bayes classifier is that it is easy to implement. The major advantage of Na\u00efve Bayes classifier is that it has good learning speed as well as classification speed. It has modest space storage requirements. In addition incrementality is supported. Recommendations can re-done as more attribute values of the new item become known. Another advantage is that it seems to work very well in many scenarios. Na\u00efve Bayes Classifier has much wider range of applicability than previously thought, this despite using the independence assumption.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">However classification accuracy is different from probability estimate accuracy. We make the assumption of class conditional independence and therefore there is loss of accuracy because practically, dependencies exist among variables. As an example in hospitals: we can have patients who have profiles\u00a0<span style=\"font-size: 1em;text-align: initial\">based on variables such as age, family history etc , who are associated with symptoms: such as fever, cough etc., and can have diseases such as lung cancer, diabetes etc and some of these variables are not independent. Dependencies among these variables cannot be modeled by Na\u00efve Bayesian Classifier, We will tackle these dependencies later using Bayesian Belief Networks.<\/span><\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>30.12 Issues Relevant to Na\u00efve Bayes<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0 <strong>Violation of Independence Assumption<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>For many real world tasks, events are correlated, but nevertheless, na\u00efve Bayes works surprisingly well anyway.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-679\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-133.png\" alt=\"\" width=\"401\" height=\"52\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-133.png 401w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-133-300x39.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-133-65x8.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-133-225x29.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-133-350x45.png 350w\" sizes=\"auto, (max-width: 401px) 100vw, 401px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>2.\u00a0 <strong>Zero conditional probability Problem<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Such problem exists when no example contains the attribute value<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-680\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-134.png\" alt=\"\" width=\"557\" height=\"148\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-134.png 557w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-134-300x80.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-134-65x17.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-134-225x60.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-134-350x93.png 350w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/p>\n<p style=\"text-align: justify\">during test. One solution to the issue is to estimate conditional probabilities with virtual examples. We have estimated probabilities by the fraction of times the event is observed to <em>n<\/em><em>c<\/em> occur over the total number of opportunities <em>n. However<\/em> this provides poor estimates when <em>n<\/em><em>c<\/em> is very small. What happens if none of the training instances with target value <em>v<\/em><em>j<\/em> have attribute value <em>a<\/em><em>i<\/em>? In other words <em>n<\/em><em>c<\/em> is 0.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">When <em>n<\/em><em>c<\/em> is very small we calculate likelihood as follows :<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-681\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-135.png\" alt=\"\" width=\"293\" height=\"77\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-135.png 293w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-135-65x17.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-135-225x59.png 225w\" sizes=\"auto, (max-width: 293px) 100vw, 293px\" \/><\/p>\n<p style=\"text-align: justify\"><em>Here n <\/em>is number of training examples for which<em> v=v<\/em><em>j<\/em><em> , n<\/em><em>c<\/em> number of examples for which <em>v=v<\/em><em>j<\/em> and <em>a=a<\/em><em>i,<\/em> <em>p<\/em> is <strong>prior<\/strong> estimate and <em>m<\/em> is weight given to prior (i.e. number of &#8220;virtual&#8221; examples) .<\/p>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-682\" src=\"http:\/\/csp15.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/65\/2019\/01\/2-136.png\" alt=\"\" width=\"403\" height=\"67\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-136.png 403w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-136-300x50.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-136-65x11.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-136-225x37.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-content\/uploads\/sites\/65\/2019\/01\/2-136-350x58.png 350w\" sizes=\"auto, (max-width: 403px) 100vw, 403px\" \/><\/p>\n<p><strong>Summary<\/strong><\/p>\n<ul>\n<li>Explained the concept of Probabilistic Classification<\/li>\n<li>Described Na\u00efve Bayes Classifier<\/li>\n<li>Discussed some applications of Na\u00efve Bayes Classifier<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Web Links<\/strong><\/p>\n<ul>\n<li>studentnet.cs.manchester.ac.uk\/ugt\/COMP24111\/&#8230;\/Naive-Bayes.ppt<\/li>\n<li>web.cecs.pdx.edu\/&#8230;\/2015BayesTrees&#8230;\/2014_0095_Example%20of%20<\/li>\n<li>https:\/\/cse.sc.edu\/~rose\/587\/PPT\/NaiveBayes.ppt<\/li>\n<li>www.cs.unc.edu\/~lazebnik\/spring09\/lec20_generative.ppt<\/li>\n<li>cis-linux1.temple.edu\/~latecki\/Courses\/RobotFall08\/&#8230;\/bayesNaive.ppt<\/li>\n<li>www.cs.bu.edu\/fac\/gkollios\/ada01\/LectNotes\/Bayesian.ppt<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Supporting &amp; Reference Materials<\/strong><\/p>\n<ul>\n<li>Tom <a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Mitchell&amp;search-alias=stripbooks\">Mitchell, <\/a>\u201cMachine Learning\u201d,McGraw-Hill Education, 1997<\/li>\n<li><a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Alpaydin+Ethem&amp;search-alias=stripbooks\">AlpaydinEthem, <\/a>\u201cIntroduction to Machine Learning\u201d, The MIT Press; third edition, 2014<\/li>\n<li>Christopher M. <a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Bishop&amp;search-alias=stripbooks\">Bishop, <\/a>\u201cPattern Recognition and Machine Learning\u201d,Springer, 2013 <a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Peter+Harrington&amp;search-alias=stripbooks\">Peter Harrington, <\/a>\u201cMachine Learning In Action\u201d, Manning Publications, 2012<\/li>\n<li><a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Peter+Flach&amp;search-alias=stripbooks\">Peter Flach, <\/a>\u201cMachine Learning: The Art and Science of Algorithms that Make Sense of Data\u201d,Cambridge University Press, 2012<\/li>\n<li><a href=\"http:\/\/www.amazon.in\/s\/ref=dp_byline_sr_book_1?ie=UTF8&amp;field-author=Stephen+Marsland&amp;search-alias=stripbooks\">Stephen Marsland, <\/a>\u201cMachine Learning: An Algorithmic Perspective\u201d, Chapman and Hall\/CRC; 2 edition, 2014<\/li>\n<li>S. Abu-Mostafa, M. Magdon-Ismail, and H.-T. Lin, \u201cLearning from Data\u201d, AMLBook, 2012.<\/li>\n<\/ul>\n","protected":false},"author":3,"menu_order":29,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-648","chapter","type-chapter","status-publish","hentry"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters\/648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/users\/3"}],"version-history":[{"count":5,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters\/648\/revisions"}],"predecessor-version":[{"id":684,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters\/648\/revisions\/684"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapters\/648\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/media?parent=648"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/pressbooks\/v2\/chapter-type?post=648"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/contributor?post=648"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp15\/wp-json\/wp\/v2\/license?post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}