Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with Python for the Internet of Things

You're reading from   Getting Started with Python for the Internet of Things Leverage the full potential of Python to prototype and build IoT projects using the Raspberry Pi

Arrow left icon
Product type Course
Published in Feb 2019
Publisher
ISBN-13 9781838555795
Length 732 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (5):
Arrow left icon
Tim Cox Tim Cox
Author Profile Icon Tim Cox
Tim Cox
Prof. Diwakar Vaish Prof. Diwakar Vaish
Author Profile Icon Prof. Diwakar Vaish
Prof. Diwakar Vaish
Sai Yamanoor Sai Yamanoor
Author Profile Icon Sai Yamanoor
Sai Yamanoor
Steven Lawrence Fernandes Steven Lawrence Fernandes
Author Profile Icon Steven Lawrence Fernandes
Steven Lawrence Fernandes
Srihari Yamanoor Srihari Yamanoor
Author Profile Icon Srihari Yamanoor
Srihari Yamanoor
+1 more Show less
Arrow right icon
View More author details
Toc

Table of Contents (37) Chapters Close

Title Page
Copyright and Credits
About Packt
Contributors
Preface
1. Getting Started with a Raspberry Pi 3 Computer FREE CHAPTER 2. Dividing Text Data and Building Text Classifiers 3. Using Python for Automation and Productivity 4. Predicting Sentiments in Words 5. Detecting Edges and Contours in Images 6. Building Face Detector and Face Recognition Applications 7. Using Python to Drive Hardware 8. Sensing and Displaying Real-World Data 9. Building Neural Network Modules for Optical Character Recognition 10. Arithmetic Operations, Loops, and Blinky Lights 11. Conditional Statements, Functions, and Lists 12. Communication Interfaces 13. Data Types and Object-Oriented Programming in Python 14. File I/O and Python Utilities 15. Requests and Web Frameworks 16. Awesome Things You Could Develop Using Python 17. Robotics 101 18. Using GPIOs as Input 19. Making a Gardener Robot 20. Basics of Motors 21. Bluetooth-Controlled Robotic Car 22. Sensor Interface for Obstacle Avoidance 23. Making Your Own Area Scanner 24. Basic Switching 25. Recognizing Humans with Jarvis 26. Making Jarvis IoT Enabled 27. Giving Voice to Jarvis 28. Gesture Recognition 29. Machine Learning 30. Making a Robotic Arm 1. Other Books You May Enjoy Index

Splitting the dataset for training and testing


Splitting helps to partition the dataset into training and testing sequences.

How to do it...

  1. Add the following code fragment into the same Python file:
from sklearn import cross_validation
from sklearn.naive_bayes import GaussianNB
import numpy as np
import matplotlib.pyplot as plt
in_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:
b_test_pred = classification_gaussiannb_new.predict(a_testing)
  1. Compute the accuracy of the classifier system:
correctness...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image