Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Raspberry Pi 3 Cookbook for Python Programmers
Raspberry Pi 3 Cookbook for Python Programmers

Raspberry Pi 3 Cookbook for Python Programmers: Unleash the potential of Raspberry Pi 3 with over 100 recipes , Third Edition

Arrow left icon
Profile Icon Steven Lawrence Fernandes Profile Icon Tim Cox
Arrow right icon
€15.99 €23.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (10 Ratings)
eBook Apr 2018 552 pages 3rd Edition
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Steven Lawrence Fernandes Profile Icon Tim Cox
Arrow right icon
€15.99 €23.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (10 Ratings)
eBook Apr 2018 552 pages 3rd Edition
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Raspberry Pi 3 Cookbook for Python Programmers

Dividing Text Data and Building Text Classifiers

This chapter presents the following recipes:

  • Building a text classifier
  • Preprocessing data using tokenization
  • Stemming text data
  • Dividing text using chunking
  • Building a bag-of-words model
  • Applications of text classifiers

Introduction

This chapter presents recipes to build text classifiers. This includes extracting vital features from the database, training, testing, and validating the text classifier. Initially, a text classifier is trained using commonly used words. Later, the trained text classifier is used for prediction. Building a text classifier includes preprocessing the data using tokenization, stemming text data, dividing text using chunking, and building a bag-of-words model.

Building a text classifier

Classifier units are normally considered to separate a database into various classes. The Naive Bayes classifier scheme is widely considered in literature to segregate the texts based on the trained model. This section of the chapter initially considers a text database with keywords; feature extraction extracts the key phrases from the text and trains the classifier system. Then, term frequency-inverse document frequency (tf-idf) transformation is implemented to specify the importance of the word. Finally, the output is predicted and printed using the classifier system.

How to do it...

  1. Include the following lines in a new Python file to add datasets:
from sklearn.datasets import fetch_20newsgroups...

Pre-processing data using tokenization

The pre-processing of data involves converting the existing text into acceptable information for the learning algorithm.

Tokenization is the process of dividing text into a set of meaningful pieces. These pieces are called tokens.

How to do it...

  1. Introduce sentence tokenization:
from nltk.tokenize import sent_tokenize
  1. Form a new text tokenizer:
tokenize_list_sent = sent_tokenize(text)
print "nSentence tokenizer:" print tokenize_list_sent
  1. Form a new word tokenizer:
from nltk.tokenize import word_tokenize 
print "nWord tokenizer:" 
print word_tokenize(text) 
  1. Introduce a new WordPunct tokenizer:
from nltk.tokenize import WordPunctTokenizer 
word_punct_tokenizer...

Stemming text data

The stemming procedure involves creating a suitable word with reduced letters for the words of the tokenizer.

How to do it...

  1. Initialize the stemming process with a new Python file:
from nltk.stem.porter import PorterStemmer 
from nltk.stem.lancaster import LancasterStemmer 
from nltk.stem.snowball import SnowballStemmer 
  1. Let's describe some words to consider, as follows:
words = ['ability', 'baby', 'college', 'playing', 'is', 'dream', 'election', 'beaches', 'image', 'group', 'happy'] 
  1. Identify a group of stemmers to be used:
stemmers = ['PORTER', 'LANCASTER', &apos...

Dividing text using chunking

The chunking procedure can be used to divide the large text into small, meaningful words.

How to do it...

  1. Develop and import the following packages using Python:
import numpy as np 
from nltk.corpus import brown 
  1. Describe a function that divides text into chunks:
# Split a text into chunks 
def splitter(content, num_of_words): 
   words = content.split(' ') 
   result = [] 
  1. Initialize the following programming lines to get the assigned variables:
   current_count = 0 
   current_words = []
  1. Start the iteration using words:
   for word in words: 
     current_words.append(word) 
     current_count += 1 
  1. After getting the essential amount of words, reorganize the variables:
  ...

Building a bag-of-words model

When working with text documents that include large words, we need to switch them to several types of arithmetic depictions. We need to formulate them to be suitable for machine learning algorithms. These algorithms require arithmetical information so that they can examine the data and provide significant details. The bag-of-words procedure helps us to achieve this. Bag-of-words creates a text model that discovers vocabulary using all the words in the document. Later, it creates the models for every text by constructing a histogram of all the words in the text.

How to do it...

  1. Initialize a new Python file by importing the following file:
import numpy as np 
from nltk.corpus import brown 
from...

Applications of text classifiers

Text classifiers are used to analyze customer sentiments, in product reviews, when searching queries on the internet, in social tags, to predict the novelty of research articles, and so on.

Left arrow icon Right arrow icon

Key benefits

  • Leverage the power of Raspberry Pi 3 using Python programming
  • Create 3D games, build neural network modules, and interface with your own circuits
  • Packed with clear, step-by-step recipes to walk you through the capabilities of Raspberry Pi

Description

Raspberry Pi 3 Cookbook for Python Programmers – Third Edition begins by guiding you through setting up Raspberry Pi 3, performing tasks using Python 3.6, and introducing the first steps to interface with electronics. As you work through each chapter, you will build your skills and apply them as you progress. You will learn how to build text classifiers, predict sentiments in words, develop applications using the popular Tkinter library, and create games by controlling graphics on your screen. You will harness the power of a built in graphics processor using Pi3D to generate your own high-quality 3D graphics and environments. You will understand how to connect Raspberry Pi’s hardware pins directly to control electronics, from switching on LEDs and responding to push buttons to driving motors and servos. Get to grips with monitoring sensors to gather real-life data, using it to control other devices, and viewing the results over the internet. You will apply what you have learned by creating your own Pi-Rover or Pi-Hexipod robots. You will also learn about sentiment analysis, face recognition techniques, and building neural network modules for optical character recognition. Finally, you will learn to build movie recommendations system on Raspberry Pi 3.

Who is this book for?

This book is for anyone who wants to master the skills of Python programming using Raspberry Pi 3. Prior knowledge of Python will be an added advantage.

What you will learn

  • Learn to set up and run Raspberry Pi 3
  • Build text classifiers and perform automation using Python
  • Predict sentiments in words and create games and graphics
  • Detect edges and contours in images
  • Build human face detection and recognition system
  • Use Python to drive hardware
  • Sense and display real-world data
  • Build a neural network module for optical character recognition
  • Build movie recommendations system

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 30, 2018
Length: 552 pages
Edition : 3rd
Language : English
ISBN-13 : 9781788626989
Vendor :
Raspberry Pi
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Apr 30, 2018
Length: 552 pages
Edition : 3rd
Language : English
ISBN-13 : 9781788626989
Vendor :
Raspberry Pi
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 80.97
Raspberry Pi 3 Home Automation Projects
€29.99
Raspberry Pi 3 Cookbook for Python Programmers
€29.99
Internet of Things with Raspberry Pi 3
€20.99
Total 80.97 Stars icon

Table of Contents

16 Chapters
Getting Started with a Raspberry Pi 3 Computer Chevron down icon Chevron up icon
Dividing Text Data and Building Text Classifiers Chevron down icon Chevron up icon
Using Python for Automation and Productivity Chevron down icon Chevron up icon
Predicting Sentiments in Words Chevron down icon Chevron up icon
Creating Games and Graphics Chevron down icon Chevron up icon
Detecting Edges and Contours in Images Chevron down icon Chevron up icon
Creating 3D Graphics Chevron down icon Chevron up icon
Building Face Detector and Face Recognition Applications Chevron down icon Chevron up icon
Using Python to Drive Hardware Chevron down icon Chevron up icon
Sensing and Displaying Real-World Data Chevron down icon Chevron up icon
Building Neural Network Modules for Optical Character Recognition Chevron down icon Chevron up icon
Building Robots Chevron down icon Chevron up icon
Interfacing with Technology Chevron down icon Chevron up icon
Can I Recommend a Movie for You? Chevron down icon Chevron up icon
Hardware and Software List Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Most Recent
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(10 Ratings)
5 star 60%
4 star 10%
3 star 0%
2 star 10%
1 star 20%
Filter icon Filter
Most Recent

Filter reviews by




Amazon Customer May 12, 2020
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Be ready to troubleshoot. This book never makes it clear which python version to use, and it makes it seem like it's all going to be in Python 3. Until you hit an error. Then you see all of the print statements are in python 2 style. What a frustrating way to go about learning this stuff. Absolutely not recommended for python beginners, and python pros should consider other material.
Amazon Verified review Amazon
Chris Feb 06, 2020
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Formatting is all kinds of messed up. most of the book is impossible to read.
Amazon Verified review Amazon
C. Eastman Nov 26, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great Python 3 text
Amazon Verified review Amazon
Robin T. Wernick Oct 10, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I very much liked the variety of projects and the medium resolution visual display projects. The SQLite database interfering project is relevant to several of my current projects. There were many others that caught my eye and I can't wait to read about them thoroughly.I was hoping to see more connectivity between the projects, but I have to admit that with a device, as versatile as it is, that I may be better served with the diversity of the projects.
Amazon Verified review Amazon
Angelmarauder May 29, 2019
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
On Amazon cloud reader PART of the book shows up with one character per line no matter the setting. Absolute nonsense for them to sell it with such low quality editing.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.