Skip to Content
Raspberry Pi 3 Cookbook for Python Programmers - Third Edition
book

Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

by Steven Lawrence Fernandes, Tim Cox
April 2018
Beginner content levelBeginner
552 pages
13h 58m
English
Packt Publishing
Content preview from Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

How to do it...

  1. Import the packages:
from sklearn import cross_validationfrom sklearn.naive_bayes import GaussianNBimport numpy as npin_file = 'cross_validation_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)classification_gaussiannb = GaussianNB()
  1. Compute the accuracy of the classifier:
num_of_validations = 5accuracy = cross_validation.cross_val_score(classification_gaussiannb, a, b, scoring='accuracy', cv=num_of_validations)print "Accuracy: " + str(round(100* accuracy.mean(), 2)) + "%"f1 = cross_validation.cross_val_score(classification_gaussiannb, a, b, scoring='f1_weighted', cv=num_of_validations) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Raspberry Pi for Python Programmers Cookbook - Second Edition

Raspberry Pi for Python Programmers Cookbook - Second Edition

Tim Cox

Publisher Resources

ISBN: 9781788629874Supplemental Content