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
Free Trial
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (10 Ratings)
Paperback Apr 2018 552 pages 3rd Edition
eBook
zł125.99
Paperback
zł157.99
Subscription
Free Trial
Arrow left icon
Profile Icon Steven Lawrence Fernandes Profile Icon Tim Cox
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8 (10 Ratings)
Paperback Apr 2018 552 pages 3rd Edition
eBook
zł125.99
Paperback
zł157.99
Subscription
Free Trial
eBook
zł125.99
Paperback
zł157.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788629874
Vendor :
Raspberry Pi
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 zł20 each
Feature tick icon Exclusive print discounts
$279.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 zł20 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 424.97
Raspberry Pi 3 Home Automation Projects
zł157.99
Raspberry Pi 3 Cookbook for Python Programmers
zł157.99
Internet of Things with Raspberry Pi 3
zł108.99
Total 424.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

Top Reviews
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
Top Reviews

Filter reviews by




Arturo Vásquez Feb 04, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Easy to read and follow the examples
Amazon Verified review Amazon
cnpyhi Sep 21, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Yes, the content is up to my expectations.
Amazon Verified review Amazon
james burrell Jan 24, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good
Amazon Verified review Amazon
Ian Templeton Nov 09, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very detailed would recommend.
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
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.