Book Image

Machine Learning for Mobile

By : Revathi Gopalakrishnan, Avinash Venkateswarlu
Book Image

Machine Learning for Mobile

By: Revathi Gopalakrishnan, Avinash Venkateswarlu

Overview of this book

Machine learning presents an entirely unique opportunity in software development. It allows smartphones to produce an enormous amount of useful data that can be mined, analyzed, and used to make predictions. This book will help you master machine learning for mobile devices with easy-to-follow, practical examples. You will begin with an introduction to machine learning on mobiles and grasp the fundamentals so you become well-acquainted with the subject. You will master supervised and unsupervised learning algorithms, and then learn how to build a machine learning model using mobile-based libraries such as Core ML, TensorFlow Lite, ML Kit, and Fritz on Android and iOS platforms. In doing so, you will also tackle some common and not-so-common machine learning problems with regard to Computer Vision and other real-world domains. By the end of this book, you will have explored machine learning in depth and implemented on-device machine learning with ease, thereby gaining a thorough understanding of how to run, create, and build real-time machine-learning applications on your mobile devices.
Table of Contents (19 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Question and Answers
Index

Preface

This book will help you perform machine learning on mobile with simple practical examples. You start from the basics of machine learning, and by the time you complete the book, you will have a good grasp of what mobile machine learning is and what tools/SDKs are available for implementing mobile machine learning, and will also be able to implement various machine learning algorithms in mobile applications that can be run in both iOS and Android.

You will learn what machine learning is and will understand what is driving mobile machine learning and how it is unique. You will be exposed to all the mobile machine learning tools and SDKs: TensorFlow Lite, Core ML, ML Kit, and Fritz on Android and iOS. This book will explore the high-level architecture and components of each toolkit. By the end of the book, you will have a broad understanding of machine learning models and will be able to perform on-device machine learning. You will get deep-dive insights into machine learning algorithms such as regression, classification, linear support vector machine (SVM), and random forest. You will learn how to do natural language processing and implement spam message detection. You will learn how to convert existing models created using Core ML and TensorFlow into Fritz models. You will also be exposed to neural networks. You will also get sneak peek into the future of machine learning, and the book also contains an FAQ section to answer all your queries on mobile machine learning. It will help you to build an interesting diet application that provides the calorie values of food items that are captured on a camera, which runs both in iOS and Android.

Who this book is for

Machine Learning for Mobile is for you if you are a mobile developer or machine learning user who aspires to exploit machine learning and use it on mobiles and smart devices. Basic knowledge of machine learning and entry-level experience with mobile application development is preferred.

What this book covers

Chapter 1, Introduction to Machine Learning on Mobile, explains what machine learning is and why we should use it on mobile devices. It introduces different approaches to machine learning and their pro and cons.

Chapter 2, Supervised and Unsupervised Learning Algorithms, covers supervised and unsupervised approaches of machine learning algorithms. We will also learn about different algorithms, such as Naive Bayes, decision trees, SVM, clustering, associated mapping, and many more. 

Chapter 3, Random Forest on iOS, covers random forests and decision trees in depth and explains how to apply them to solve machine learning problems. We will also create an application using a decision tree to diagnose breast cancer.

Chapter 4TensorFlow Mobile in Android, introduces TensorFlow for mobile. We will also learn about the architecture of a mobile machine learning application and write an application using TensorFlow in Android. 

Chapter 5, Regression Using Core ML in iOS, explores regression and Core ML and shows how to apply it to solve a machine learning problem. We will be creating an application using scikit-learn to predict house prices. 

Chapter 6, ML Kit SDK, explores ML Kit and its benefits. We will be creating some image labeling applications using ML Kit and device and cloud APIs. 

Chapter 7, Spam Message Detection in iOS - Core ML, introduces natural language processing and the SVM algorithm. We will solve a problem of bulk SMS, that is, whether messages are spam or not. 

Chapter 8, Fritz, introduces the Fritz mobile machine learning platform. We will create an application using Fritz and Core ML in iOS. We will also see how Fritz can be used with the sample dataset we create earlier in the book. 

Chapter 9, Neural Networks on Mobile, covers the concepts of neural networks, Keras, and their applications in the field of mobile machine learning. We will be creating an application to recognize handwritten digits and also the TensorFlow image recognition model.

Chapter 10Mobile Application Using Google Cloud Vision, introduces the Google Cloud Vision label-detection technique in an Android application to determine what is in pictures taken by a camera.

Chapter 11Future of ML on Mobile Applications, covers the key features of mobile applications and the opportunities they provide for stakeholders.

Appendix, Question and Answers, contains questions that may be on your mind and tries to provide answers to those questions.

To get the most out of this book

Readers need to have prior knowledge of machine learning, Android Studio, and Xcode.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Machine-Learning-for-Mobile. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

 

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781788629355_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Now you can take the generated SpamMessageClassifier.mlmodel file and use this in your Xcode."

A block of code is set as follows:

# importing required packages
import numpy as np
import pandas as pd

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

# Reading in and parsing data
raw_data = open('SMSSpamCollection.txt', 'r')
sms_data = []
for line in raw_data:
    split_line = line.split("\t")
    sms_data.append(split_line)

Any command-line input or output is written as follows:

pip install scikit-learn 
pip install numpy
pip install coremltools
pip install pandas

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.