Implementation of Gaussian Naive Bayes in Python from scratch

Learn, Code and Execute…

Navoneel Chakrabarty
HackerNoon.com
Published in
6 min readJan 23, 2019

--

Naive Bayes is a very handy, popular and important Machine Learning Algorithm especially for Text Analytics and General Classification. It has many different configurations namely:

  1. Gaussian Naive Bayes
  2. Multinomial Naive Bayes
  3. Complement Naive Bayes
  4. Bernoulli Naive Bayes
  5. Out-of-core Naive Bayes

In this article, I am going to discuss Gaussian Naive Bayes: the algorithm, its implementation and application in a miniature Wikipedia Dataset (dataset given in Wikipedia).

The Algorithm:

Gaussian Naive Bayes is an algorithm having a Probabilistic Approach. It involves prior and posterior probability calculation of the classes in the dataset and the test data given a class respectively.

Prior probabilities of all the classes are calculated using the same formula.

But, how to obtain the conditional probabilities of the test data features given a class?

This is given by the probability obtained from Gaussian (Normal) Distribution.

Finally, the conditional probability of each class given an instance (test…

--

--

Navoneel Chakrabarty
HackerNoon.com

Data Mining | Data Analytics | Machine Learning | Financial Data Science | Natural Language Processing | Deep Learning