{"id":1468,"date":"2021-04-01T16:15:39","date_gmt":"2021-04-01T10:45:39","guid":{"rendered":"https:\/\/dphi.tech\/blog\/?p=1468"},"modified":"2022-11-15T14:59:00","modified_gmt":"2022-11-15T09:29:00","slug":"naive-bayes-algorithm-everything-you-need-to-know","status":"publish","type":"post","link":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/","title":{"rendered":"Na\u00efve Bayes Algorithm \u2014 Everything you need to know"},"content":{"rendered":"\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"656\" data-id=\"1469\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium.jpg\" alt=\"\" class=\"wp-image-1469\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium-300x192.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium-768x492.jpg 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<figcaption class=\"blocks-gallery-caption\"><a rel=\"noreferrer noopener\" href=\"https:\/\/blogs.oracle.com\/datascience\/introduction-to-bayesian-inference\" target=\"_blank\">Credits<\/a><\/figcaption><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"viewer-asun4\">Introduction<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The simplest solutions are usually the most powerful ones, and Na\u00efve Bayes is a good example of that. Despite the advances in Machine Learning in the last years, it has proven to not only be simple but also fast, accurate, and reliable. It has been successfully used for many purposes, but it works particularly well with natural language processing (NLP) problems.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Na\u00efve Bayes is a probabilistic machine learning algorithm based on the <strong>Bayes Theorem<\/strong>, used in a wide variety of classification tasks. In this article, we will understand the Na\u00efve Bayes algorithm and all essential concepts so that there is no room for doubts in understanding.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"viewer-f8gnq\">Bayes Theorem<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Bayes\u2019 Theorem is a simple mathematical formula used for calculating conditional probabilities.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conditional probability<\/strong> is a measure of the probability of an event occurring given that another event has (by assumption, presumption, assertion, or evidence) occurred.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The formula is: \u2014<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"965\" height=\"582\" data-id=\"1470\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155613.jpg\" alt=\"\" class=\"wp-image-1470\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155613.jpg 965w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155613-300x181.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155613-768x463.jpg 768w\" sizes=\"(max-width: 965px) 100vw, 965px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Which tells us: how often A happens <em>given that B happens<\/em>, written <strong>P(A|B) <\/strong>also called posterior probability, When we know: how often B happens <em>given that A happens<\/em>, written <strong>P(B|A)<\/strong> and how likely A is on its own, written <strong>P(A)<\/strong> and how likely B is on its own, written <strong>P(B).<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><em>In simpler terms, Bayes\u2019 Theorem is a way of finding a probability when we know certain other probabilities.<\/em><\/p><\/blockquote>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"viewer-36kip\">Assumptions made by Na\u00efve Bayes<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The fundamental Na\u00efve Bayes assumption is that each feature makes an:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>independent<\/li><li>equal<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">contribution to the outcome.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let us take an example to get some better intuition. Consider the car theft problem with attributes Color, Type, Origin, and the target, Stolen can be either Yes or No.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"viewer-bcmj8\">Example<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The dataset is represented as below.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"947\" height=\"531\" data-id=\"1471\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155727.jpg\" alt=\"\" class=\"wp-image-1471\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155727.jpg 947w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155727-300x168.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155727-768x431.jpg 768w\" sizes=\"(max-width: 947px) 100vw, 947px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Concerning our dataset, the concept of assumptions made by the algorithm can be understood as:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>We assume that no pair of features are dependent. For example, the color being \u2018Red\u2019 has nothing to do with the Type or the Origin of the car. Hence, the features are assumed to be <strong>Independent<\/strong>.<\/li><li>Secondly, each feature is given the same influence(or importance). For example, knowing the only Color and Type alone can\u2019t predict the outcome perfectly. So none of the attributes are irrelevant and assumed to be contributing <strong>Equally<\/strong> to the outcome.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> The assumptions made by Na\u00efve Bayes are generally not correct in real-world situations. The independence assumption is never correct but often works well in practice. <strong>Hence the name \u2018Na<\/strong>\u00ef<strong>ve\u2019.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here in our dataset, <strong>we need to classify whether the car is stolen, given the features of the car<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The columns represent these features and the rows represent individual entries. If we take the first row of the dataset, we can observe that the car is stolen if the Color is Red, the Type is Sports and the Origin is Domestic. So we want to classify a Red Domestic SUV is getting stolen or not. Note that there is no example of a Red Domestic SUV in our data set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">According to this example, Bayes theorem can be rewritten as:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"768\" height=\"171\" data-id=\"1472\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155837.jpg\" alt=\"\" class=\"wp-image-1472\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155837.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155837-300x67.jpg 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The variable <strong>y<\/strong> is the class variable(stolen?), which represents if the car is stolen or not given the conditions. Variable <strong>X <\/strong>represents the parameters\/features.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>X<\/strong> is given as,<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"871\" height=\"133\" data-id=\"1473\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155926.jpg\" alt=\"\" class=\"wp-image-1473\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155926.jpg 871w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155926-300x46.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-155926-768x117.jpg 768w\" sizes=\"(max-width: 871px) 100vw, 871px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here x1,x2\u2026.xn represent the features, i.e they can be mapped to Color, Type, and Origin. By substituting for <strong>X <\/strong>and expanding using the chain rule we get,<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-6 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"127\" data-id=\"1474\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160023-1024x127.jpg\" alt=\"\" class=\"wp-image-1474\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160023-1024x127.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160023-300x37.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160023-768x95.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160023.jpg 1086w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you can obtain the values for each by looking at the dataset and substitute them into the equation. For all entries in the dataset, the denominator does not change, it remains static. Therefore, the denominator can be removed and proportionality can be injected.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-7 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"131\" data-id=\"1475\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160107-1024x131.jpg\" alt=\"\" class=\"wp-image-1475\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160107-1024x131.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160107-300x38.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160107-768x98.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160107.jpg 1082w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In our case, the class variable(<strong>y<\/strong>) has only two outcomes, yes or no. There could be cases where the classification could be multivariate. Therefore, we have to find the class variable(<strong>y)<\/strong> with maximum probability.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-8 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"130\" data-id=\"1476\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160158-1024x130.jpg\" alt=\"\" class=\"wp-image-1476\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160158-1024x130.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160158-300x38.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160158-768x97.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160158.jpg 1082w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Using the above function, we can obtain the class, given the predictors\/features.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The posterior probability <strong>P(y|X)<\/strong> can be calculated by first, creating a <strong>Frequency Table<\/strong> for each attribute against the target. Then, molding the frequency tables to <strong>Likelihood Tables<\/strong> and finally, use the Na\u00efve Bayesian equation to calculate the posterior probability for each class. The class with the highest posterior probability is the outcome of the prediction. Below are the Frequency and likelihood tables for all three predictors.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-9 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"516\" data-id=\"1477\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160247-1024x516.jpg\" alt=\"\" class=\"wp-image-1477\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160247-1024x516.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160247-300x151.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160247-768x387.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160247.jpg 1033w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-10 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"518\" data-id=\"1478\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160346-1024x518.jpg\" alt=\"\" class=\"wp-image-1478\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160346-1024x518.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160346-300x152.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160346-768x389.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160346.jpg 1033w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-11 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"518\" data-id=\"1479\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160437-1024x518.jpg\" alt=\"\" class=\"wp-image-1479\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160437-1024x518.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160437-300x152.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160437-768x389.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160437.jpg 1027w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So in our example, we have 3 predictors <strong>X<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-12 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"713\" data-id=\"1480\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160530.jpg\" alt=\"\" class=\"wp-image-1480\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160530.jpg 852w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160530-300x251.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160530-768x643.jpg 768w\" sizes=\"(max-width: 852px) 100vw, 852px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Since 0.144 &gt; 0.048, Which means given the features RED SUV and Domestic, our example gets classified as \u2019NO\u2019 the car is not stolen.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"viewer-b5l3v\">The zero-frequency problem<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">One of the disadvantages of Na\u00efve-Bayes is that if you have no occurrences of a class label and a certain attribute value together then the frequency-based probability estimate will be zero. And this will get a zero when all the probabilities are multiplied.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An approach to overcome this \u2018zero-frequency problem\u2019 in a Bayesian environment is to add one to the count for every attribute value-class combination when an attribute value doesn\u2019t occur with every class value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, say your training data looked like this:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-13 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"568\" height=\"138\" data-id=\"1481\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160629.jpg\" alt=\"\" class=\"wp-image-1481\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160629.jpg 568w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160629-300x73.jpg 300w\" sizes=\"(max-width: 568px) 100vw, 568px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">?(TimeZone=??|Spam=???)=10\/10=1<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">?(TimeZone=??|Spam=???)=0\/10=0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then you should add one to every value in this table when you\u2019re using it to calculate probabilities:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-14 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"140\" data-id=\"1482\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160744.jpg\" alt=\"\" class=\"wp-image-1482\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160744.jpg 565w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160744-300x74.jpg 300w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">?(TimeZone=??|Spam=???)=11\/12<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">?(TimeZone=??|Spam=???)=1\/12<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is how we\u2019ll get rid of getting a zero probability.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"viewer-ccruo\">Types of Na\u00efve Bayes Classifier:<\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Multinomial Na\u00efve Bayes<\/strong>: Feature vectors represent the frequencies with which certain events have been generated by a <strong>multinomial distribution<\/strong>. This is the event model typically used for document classification.<\/li><li><strong>Bernoulli Na\u00efve Bayes<\/strong>: In the multivariate Bernoulli event model, features are independent booleans (binary variables) describing inputs. Like the multinomial model, this model is popular for document classification tasks, where binary term occurrence(i.e. a word occurs in a document or not) features are used rather than term frequencies(i.e. frequency of a word in the document).<\/li><li><strong>Gaussian Na\u00efve Bayes: <\/strong>In Gaussian Na\u00efve Bayes, continuous values associated with each feature are assumed to be distributed according to a <strong>Gaussian distribution(<\/strong>Normal distribution<strong>)<\/strong>. When plotted, it gives a bell-shaped curve which is symmetric about the mean of the feature values as shown below:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-15 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"943\" height=\"546\" data-id=\"1483\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160835.jpg\" alt=\"\" class=\"wp-image-1483\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160835.jpg 943w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160835-300x174.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160835-768x445.jpg 768w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The likelihood of the features is assumed to be Gaussian, hence, conditional probability is given by:<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-16 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"688\" height=\"236\" data-id=\"1484\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160920.jpg\" alt=\"\" class=\"wp-image-1484\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160920.jpg 688w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-160920-300x103.jpg 300w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now, what if any feature contains numerical values instead of categories i.e. Gaussian distribution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One option is to transform the numerical values to their categorical counterparts before creating their frequency tables. The other option, as shown above, could be using the distribution of the numerical variable to have a good guess of the frequency. For example, one common method is to assume normal or gaussian distributions for numerical variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The probability density function for the normal distribution is defined by two parameters (mean and standard deviation).<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-17 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"343\" height=\"195\" data-id=\"1485\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Bayes_NormDist.png\" alt=\"\" class=\"wp-image-1485\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Bayes_NormDist.png 343w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Bayes_NormDist-300x171.png 300w\" sizes=\"(max-width: 343px) 100vw, 343px\" \/><\/figure>\n<figcaption class=\"blocks-gallery-caption\"><a rel=\"noreferrer noopener\" href=\"https:\/\/www.saedsayad.com\/naive_bayesian.htm\" target=\"_blank\">Credits<\/a><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Consider the problem of playing golf, here the only predictor is Humidity, and Play Golf? is the target. Using the above formula we can calculate posterior probability if we know the mean and standard deviation.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-18 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"797\" height=\"420\" data-id=\"1486\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161139.jpg\" alt=\"\" class=\"wp-image-1486\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161139.jpg 797w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161139-300x158.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161139-768x405.jpg 768w\" sizes=\"(max-width: 797px) 100vw, 797px\" \/><\/figure>\n<\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"viewer-jafs\">Case study: Na\u00efve Bayes classifier from scratch using Python<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">An existing problem for any major website today is how to handle virulent and divisive content. Quora wants to tackle this problem to keep its platform a place where users can feel safe sharing their knowledge with the world.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.quora.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"><u>Quora<\/u><\/a> is a platform that empowers people to learn from each other. On Quora, people can ask questions and connect with others who contribute unique insights and quality answers. A key challenge is to weed out insincere questions \u2014 those founded upon false premises, or that intend to make a statement rather than look for helpful answers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The goal is to develop a Na\u00efve Bayes classification model that identifies and flags insincere questions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The dataset can be downloaded from <a href=\"https:\/\/www.kaggle.com\/c\/quora-insincere-questions-classification\/data\" target=\"_blank\" rel=\"noreferrer noopener\"><u>here<\/u><\/a>. Once you have downloaded the train and test data, load it and check.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>import<\/strong> numpy <strong>as<\/strong> np\n<strong>import<\/strong> pandas <strong>as<\/strong> pd\n<strong>import<\/strong> os\ntrain <strong>=<\/strong> pd.read_csv('.\/drive\/My Drive\/train.csv')\nprint(train.head())test <strong>=<\/strong> pd.read_csv('.\/drive\/My Drive\/test.csv')<\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-19 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"365\" data-id=\"1487\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161238-1024x365.jpg\" alt=\"\" class=\"wp-image-1487\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161238-1024x365.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161238-300x107.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161238-768x274.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161238.jpg 1117w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let us see how are sincere questions look like.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-20 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"266\" data-id=\"1488\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161323-1024x266.jpg\" alt=\"\" class=\"wp-image-1488\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161323-1024x266.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161323-300x78.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161323-768x199.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161323.jpg 1122w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">we see how are insincere questions look like.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-21 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"260\" data-id=\"1489\" src=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161426-1024x260.jpg\" alt=\"\" class=\"wp-image-1489\" srcset=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161426-1024x260.jpg 1024w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161426-300x76.jpg 300w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161426-768x195.jpg 768w, https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/Screenshot-2021-04-01-161426.jpg 1112w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Text Preprocessing:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next step is to preprocess text before splitting the dataset into a train and test set. The preprocessing steps involve: Removing Numbers, Removing Punctuations in a string, Removing Stop Words, Stemming of Words, and Lemmatization of Words.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Constructing a Naive Bayes Classifier:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Combine all the preprocessing techniques and create a dictionary of words and each word\u2019s count in training data.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Calculate probability for each word in a text and filter the words which have a probability less than threshold probability. Words with probability less than threshold probability are irrelevant.<\/li><li>Then for each word in the dictionary, create a probability of that word being in insincere questions and its probability insincere questions. Then finding the conditional probability to use in naive Bayes classifier.<\/li><li>Prediction using conditional probabilities.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">You can checkout python code in this repository: <a href=\"https:\/\/gist.github.com\/nageshsinghc4\/4c9334815f904b1b6857e8d610c1e92d\" target=\"_blank\" rel=\"noreferrer noopener\"><u><strong>https:\/\/gist.github.com\/nageshsinghc4\/4c9334815f904b1b6857e8d610c1e92d<\/strong><\/u><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"viewer-b84i9\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Na\u00efve Bayes algorithms are often used in sentiment analysis, spam filtering, recommendation systems, etc. They are quick and easy to implement but their biggest disadvantage is that the requirement of predictors to be independent.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"viewer-9rh17\">Thanks for Reading!!!<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong>Note:\u00a0<\/strong>T<em>his article was originally published on\u00a0<a href=\"https:\/\/www.theaidream.com\/post\/na%C3%AFve-bayes-algorithm-everything-you-need-to-know\">theaidream<\/a>, and kindly contributed to AI Planet (formerly DPhi) to spread the knowledge.<\/em><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The simplest solutions are usually the most powerful ones, and Na\u00efve Bayes is a good example of that. Despite the advances in Machine Learning in the last years, it has proven to not only be simple but also fast, accurate, and reliable. It has been successfully used for many purposes, but it works particularly [&hellip;]<\/p>\n","protected":false},"author":23,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20,22,61],"class_list":["post-1468","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-datascience","tag-machine-learning","tag-naive-bayes"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Na\u00efve Bayes Algorithm \u2014 Everything you need to know - AI Planet<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Na\u00efve Bayes Algorithm \u2014 Everything you need to know - AI Planet\" \/>\n<meta property=\"og:description\" content=\"Introduction The simplest solutions are usually the most powerful ones, and Na\u00efve Bayes is a good example of that. Despite the advances in Machine Learning in the last years, it has proven to not only be simple but also fast, accurate, and reliable. It has been successfully used for many purposes, but it works particularly [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/\" \/>\n<meta property=\"og:site_name\" content=\"AI Planet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/aiplanet\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-01T10:45:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-15T09:29:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium.jpg\" \/>\n<meta name=\"author\" content=\"Nagesh Singh Chauhan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nagesh Singh Chauhan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/\"},\"author\":{\"name\":\"Nagesh Singh Chauhan\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#\\\/schema\\\/person\\\/f7f7394ec66e5136b2b07cc29ebf1fb8\"},\"headline\":\"Na\u00efve Bayes Algorithm \u2014 Everything you need to know\",\"datePublished\":\"2021-04-01T10:45:39+00:00\",\"dateModified\":\"2022-11-15T09:29:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/\"},\"wordCount\":1553,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/bayes27_theorem_mmb_01_Medium.jpg\",\"keywords\":[\"datascience\",\"machine learning\",\"naive bayes\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/\",\"name\":\"Na\u00efve Bayes Algorithm \u2014 Everything you need to know - AI Planet\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/bayes27_theorem_mmb_01_Medium.jpg\",\"datePublished\":\"2021-04-01T10:45:39+00:00\",\"dateModified\":\"2022-11-15T09:29:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/#primaryimage\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/bayes27_theorem_mmb_01_Medium.jpg\",\"contentUrl\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/bayes27_theorem_mmb_01_Medium.jpg\",\"width\":1024,\"height\":656},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/naive-bayes-algorithm-everything-you-need-to-know\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Na\u00efve Bayes Algorithm \u2014 Everything you need to know\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/\",\"name\":\"AI Planet, Formerly DPhi\",\"description\":\"AI Planet (formerly DPhi) is a global ecosystem that aims to educate and empower individuals and organizations to build and utilize artificial intelligence (AI). With a community of over 300,000 AI specialists and enthusiasts, we offer a range of products and have helped drive innovative solutions for various industries. Our ultimate goal is to make AI education accessible to everyone and use AI to tackle important business and social challenges.\",\"publisher\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#organization\",\"name\":\"AI Planet, Formerly DPhi\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/Size48-Large-1.png\",\"contentUrl\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/Size48-Large-1.png\",\"width\":48,\"height\":48,\"caption\":\"AI Planet, Formerly DPhi\"},\"image\":{\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/aiplanet\\\/\",\"https:\\\/\\\/www.instagram.com\\\/aiplanet_community\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/aiplanet\\\/\",\"https:\\\/\\\/www.youtube.com\\\/@aiplanet\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/#\\\/schema\\\/person\\\/f7f7394ec66e5136b2b07cc29ebf1fb8\",\"name\":\"Nagesh Singh Chauhan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b8a063fd73beeb4a06ec6a22acb32b5ceeb60ee5896f3583d09eaf03ffc7537b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b8a063fd73beeb4a06ec6a22acb32b5ceeb60ee5896f3583d09eaf03ffc7537b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b8a063fd73beeb4a06ec6a22acb32b5ceeb60ee5896f3583d09eaf03ffc7537b?s=96&d=mm&r=g\",\"caption\":\"Nagesh Singh Chauhan\"},\"description\":\"Nagesh is Medium's Official Top writer in Artificial Intelligence. He loves to share knowledge through his articles and comes with rich experience across various domains related to Data Science, Machine learning, Neural networks, Text Analysis, NLP and others.\",\"url\":\"https:\\\/\\\/aiplanet.com\\\/blog\\\/author\\\/nagesh\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Na\u00efve Bayes Algorithm \u2014 Everything you need to know - AI Planet","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/","og_locale":"en_US","og_type":"article","og_title":"Na\u00efve Bayes Algorithm \u2014 Everything you need to know - AI Planet","og_description":"Introduction The simplest solutions are usually the most powerful ones, and Na\u00efve Bayes is a good example of that. Despite the advances in Machine Learning in the last years, it has proven to not only be simple but also fast, accurate, and reliable. It has been successfully used for many purposes, but it works particularly [&hellip;]","og_url":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/","og_site_name":"AI Planet","article_publisher":"https:\/\/www.facebook.com\/aiplanet\/","article_published_time":"2021-04-01T10:45:39+00:00","article_modified_time":"2022-11-15T09:29:00+00:00","og_image":[{"url":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium.jpg","type":"","width":"","height":""}],"author":"Nagesh Singh Chauhan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nagesh Singh Chauhan","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/#article","isPartOf":{"@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/"},"author":{"name":"Nagesh Singh Chauhan","@id":"https:\/\/aiplanet.com\/blog\/#\/schema\/person\/f7f7394ec66e5136b2b07cc29ebf1fb8"},"headline":"Na\u00efve Bayes Algorithm \u2014 Everything you need to know","datePublished":"2021-04-01T10:45:39+00:00","dateModified":"2022-11-15T09:29:00+00:00","mainEntityOfPage":{"@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/"},"wordCount":1553,"commentCount":0,"publisher":{"@id":"https:\/\/aiplanet.com\/blog\/#organization"},"image":{"@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/#primaryimage"},"thumbnailUrl":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium.jpg","keywords":["datascience","machine learning","naive bayes"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/","url":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/","name":"Na\u00efve Bayes Algorithm \u2014 Everything you need to know - AI Planet","isPartOf":{"@id":"https:\/\/aiplanet.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/#primaryimage"},"image":{"@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/#primaryimage"},"thumbnailUrl":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium.jpg","datePublished":"2021-04-01T10:45:39+00:00","dateModified":"2022-11-15T09:29:00+00:00","breadcrumb":{"@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/#primaryimage","url":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium.jpg","contentUrl":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2021\/04\/bayes27_theorem_mmb_01_Medium.jpg","width":1024,"height":656},{"@type":"BreadcrumbList","@id":"https:\/\/aiplanet.com\/blog\/naive-bayes-algorithm-everything-you-need-to-know\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/aiplanet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Na\u00efve Bayes Algorithm \u2014 Everything you need to know"}]},{"@type":"WebSite","@id":"https:\/\/aiplanet.com\/blog\/#website","url":"https:\/\/aiplanet.com\/blog\/","name":"AI Planet, Formerly DPhi","description":"AI Planet (formerly DPhi) is a global ecosystem that aims to educate and empower individuals and organizations to build and utilize artificial intelligence (AI). With a community of over 300,000 AI specialists and enthusiasts, we offer a range of products and have helped drive innovative solutions for various industries. Our ultimate goal is to make AI education accessible to everyone and use AI to tackle important business and social challenges.","publisher":{"@id":"https:\/\/aiplanet.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/aiplanet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/aiplanet.com\/blog\/#organization","name":"AI Planet, Formerly DPhi","url":"https:\/\/aiplanet.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/aiplanet.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2022\/11\/Size48-Large-1.png","contentUrl":"https:\/\/aiplanet.com\/blog\/wp-content\/uploads\/2022\/11\/Size48-Large-1.png","width":48,"height":48,"caption":"AI Planet, Formerly DPhi"},"image":{"@id":"https:\/\/aiplanet.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/aiplanet\/","https:\/\/www.instagram.com\/aiplanet_community\/","https:\/\/www.linkedin.com\/company\/aiplanet\/","https:\/\/www.youtube.com\/@aiplanet"]},{"@type":"Person","@id":"https:\/\/aiplanet.com\/blog\/#\/schema\/person\/f7f7394ec66e5136b2b07cc29ebf1fb8","name":"Nagesh Singh Chauhan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b8a063fd73beeb4a06ec6a22acb32b5ceeb60ee5896f3583d09eaf03ffc7537b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b8a063fd73beeb4a06ec6a22acb32b5ceeb60ee5896f3583d09eaf03ffc7537b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b8a063fd73beeb4a06ec6a22acb32b5ceeb60ee5896f3583d09eaf03ffc7537b?s=96&d=mm&r=g","caption":"Nagesh Singh Chauhan"},"description":"Nagesh is Medium's Official Top writer in Artificial Intelligence. He loves to share knowledge through his articles and comes with rich experience across various domains related to Data Science, Machine learning, Neural networks, Text Analysis, NLP and others.","url":"https:\/\/aiplanet.com\/blog\/author\/nagesh\/"}]}},"_links":{"self":[{"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/posts\/1468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/comments?post=1468"}],"version-history":[{"count":3,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/posts\/1468\/revisions"}],"predecessor-version":[{"id":4915,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/posts\/1468\/revisions\/4915"}],"wp:attachment":[{"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/media?parent=1468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/categories?post=1468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiplanet.com\/blog\/wp-json\/wp\/v2\/tags?post=1468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}