In Machine Learning, Naive Bayes is a supervised learning classifier.
Its popular in text categorization (spam or not spam) and even competes with advanced classifiers like support vector machines.
Related course: Complete Machine Learning Course with Python
Naive Bayes classifier
In the example below we create the classifier, the training set,
then train the classifier using the training set and make a prediction.
The training set (X) simply consits of length, weight and shoe size. Y contains the associated labels (male or female).
# create dataset |
Then we train the classifier with one line:
gaunb = gaunb.fit(X, Y) |
And finally make predictions with new data.
from sklearn.naive_bayes import GaussianNB |
On the final part of the program we make a prediction with new data [190,70,43]. This then outputs the predicted value.
The phases are similar in all supervised learning classifiers:
If you predict for another set like [166, 65, 33],
you’ll get another predicted outcome.
As you may expect, it’s important to have a good training set for receiving good results.
