What is Gaussian Naive Bayes. Python implementation example



Machine learning

Release date:2024/9/7         

 ・In Japanese
Prerequisites
 ・Naive Bayes Filter
 ・python
 ・GaussianNB
 ・Gaussian distribution


This article explains how to use the Gaussian Naive Bayes filter with a practical example (see:Naive Bayes filter). The subject is classifying an insect as male or female based on its height and weight.


■What is Gaussian Naive Bayes

Gaussian Naive Bayes is a Bayes filter that assumes that the features of a certain label are Gaussian distributed. It calculates the Gaussian distribution of data belonging to the same label as shown below, and determines which distribution new data is closer to.


■Simulation of Gaussian Naive Bayes using Python

 ・python Ver:Ver3.8
 ・Required Libraries:numpy,matplotlib (For installation instructions, click here)
 ・Required filesbayes.zip(Program files, sample data)

The results are as follows. We can see that some data cannot be classified properly. This is the accuracy of the Gaussian Naive Bayes filter. More accurate classification methods include logistic regression.



<Using the scikit-learn library>
Scikit-learn has a dedicated function, GaussianNB, so we will use that.

 ・Additional required libraries:scikit-learn
 ・Additional required filesbayes2.zip(Program Files) , The sample data is the same as above

The execution result is as follows, which is the same as when not using scikit-learn.











List of related articles



Machine learning