June 2016
Beginner to intermediate
304 pages
6h 24m
English
A Naive Bayes classifier is a supervised learning classifier that uses Bayes' theorem to build the model. Let's go ahead and build a Naïve Bayes classifier.
naive_bayes.py that is provided to you as reference. Let's import a couple of things:from sklearn.naive_bayes import GaussianNB from logistic_regression import plot_classifier
data_multivar.txt file. This contains data that we will use here. This contains comma-separated numerical data in each line. Let's load the data from this file:input_file = 'data_multivar.txt' X = [] y = [] with open(input_file, 'r') as f: for line in f.readlines(): data = [float(x) for x in line.split(',')] X.append(data[:-1]) y.append(data[-1]) ...