How to do it...

  1. Add the following code fragment into the same Python file:
from sklearn import cross_validationfrom sklearn.naive_bayes import GaussianNBimport numpy as npimport matplotlib.pyplot as pltin_file = 'data_multivar.txt'a = []b = []with open(in_file, 'r') as f:  for line in f.readlines():    data = [float(x) for x in line.split(',')]    a.append(data[:-1])    b.append(data[-1])a = np.array(a)b = np.array(b)
  1. Allocate 75% of data for training and 25% of data for testing:
a_training, a_testing, b_training, b_testing = cross_validation.train_test_split(a, b, test_size=0.25, random_state=5)classification_gaussiannb_new = GaussianNB()classification_gaussiannb_new.fit(a_training, b_training)
  1. Evaluate the classifier performance on test data: ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.