Reader small image

You're reading from  Machine Learning for Mobile

Product typeBook
Published inDec 2018
PublisherPackt
ISBN-139781788629355
Edition1st Edition
Right arrow
Authors (2):
Revathi Gopalakrishnan
Revathi Gopalakrishnan
author image
Revathi Gopalakrishnan

Revathi Gopalakrishnan is a software professional with more than 17 years of experience in the IT industry. She has worked extensively in mobile application development and has played various roles, including developer and architect, and has led various enterprise mobile enablement initiatives for large organizations. She has also worked on a host of consumer applications for various customers around the globe. She has an interest in emerging areas, and machine learning is one of them. Through this book, she has tried to bring out how machine learning can make mobile application development more interesting and super cool. Revathi resides in Chennai and enjoys her weekends with her husband and her two lovely daughters.
Read more about Revathi Gopalakrishnan

Avinash Venkateswarlu
Avinash Venkateswarlu
author image
Avinash Venkateswarlu

Avinash Venkateswarlu has more than 3 years' experience in IT and is currently exploring mobile machine learning. He has worked in enterprise mobile enablement projects and is interested in emerging technologies such as mobile machine learning and cryptocurrency. Venkateswarlu works in Chennai, but enjoys spending his weekends in his home town, Nellore. He likes to do farming or yoga when he is not in front of his laptop exploring emerging technologies.
Read more about Avinash Venkateswarlu

View More author details
Right arrow

FAQs


We will organize the FAQs into three basic sections:

  • The first section will look into questions that are more generic in nature, related to data science, machine learning, and so on.
  • The second section will look into specific questions related to the different mobile machine learning frameworks.
  • The third and final section will look into specific questions related to mobile machine learning project implementation. 

Data science

In this section, we will be answering a few questions related to data science and its uses.

What is data science?

Data science is the extraction of relevant insights from data. It is a culmination of many fields, such as mathematics, machine learning, computer programming, statistical modeling, data engineering and visualization, pattern recognition and learning, uncertainty modeling, data warehousing, and cloud computing. The skills required to pursue these fields include engineering, maths, science, statistics, programming, creativity and data keeping, and maintenance.

Where is data science used?

Data science is used in Artificial Intelligence (AI) and machine learning. It solves complex data problems to bring out insights that were unknown prior to applying it. It brings out unknown correlations between data that are extremely relevant and useful to a business.

What is big data?

Big data usually includes datasets with sizes beyond the ability of commonly used software tools to capture, manage, and handle them.

Big data is characterized by the three Vs, proposed by Gartner in 2001:

  • Volume: The amount of data is enormous and increasing
  • Velocity: The rate at which the data is accumulated is rapid and increasing
  • Variety: The number of features/characteristics being captured is large and growing

Note

Gartner's 2012 definition reads: Big data is high volume, high velocity, and/or high variety information assets that require new forms of processing to enable enhanced decision making, insight discovery and process optimization.

Big data can comprise big data systems, big data analytics, and big datasets.

What is data mining?

Data mining is the process of examining large pre-existing datasets and extracting useful insights from them.

Relationship between data science and big data

Data science does not necessarily involve big data, but the fact that data is scaling up makes big data an important aspect of data science.

What are artificial neural networks?

Artificial neural networks (ANNs) are computing systems inspired by the biological neural networks that constitute animal brains. These systems are not programmed with a specific task rule, but perform tasks by considering examples without being programmed, for example, image recognition. To recognize a rose, it learns the characteristics of rose to define a sample as a rose, through learning and not through programming.

What is AI?

AI refers to the simulation of human brain functions by machines. This is achieved by creating an ANN that can show human intelligence. The primary human functions that an AI machine performs include logical reasoning, learning, and self-correction. This is a very complex field, and to make machines that are inherently not smart think and act like humans requires lot of computing power and data feeds.

AI is classified into two parts:

  • General AI: Making machines smart in wide areas, similar to humans in thinking and reasoning. This has still not been achieved today and many ongoing research activities have already been initiated.
  • Narrow AI: Making machines smart in specific areas, such as digit recognition and playing chess. This is possible today.

How are data science, AI, and machine learning interrelated?

This is an interesting and important piece of information to know, as to how exactly data science, AI, and machine learning are related to each other:

  • AI: This area is trying to mimic human intelligence artificially. Just as humans are able to see, observe the data around them, and take decisions, the same is being tried through machines. It is a very wide area. The technology is still evolving. And to achieve a small task that a human does very easily through AI, a humongous amount of data is required.
  • Machine learning: Subset of AI. Narrow focus on specific problem areas. The technology has implementations for real-life use cases. It is the connecting bridge between AI and data science.
  • Data science: It is a field of data study and extracting information from it. This can use machine learning to analyze data, big data, and so on:

Machine learning framework 

In this section, we will look at a few of the machine learning frameworks we have already gone through in the book, and the ones we have not gone through as well, and just give a few pointers on them.

Caffe2

  • Caffe2 from Facebook is one of the key mobile machine learning frameworks that was not discussed in this book. More details can be obtained from https://caffe2.ai/.
  • Caffe2 is a deep learning framework that provides an easy and straightforward way to experiment with deep learning and leverage community contributions of new models and algorithms.
  • The original Caffe framework was useful for large-scale product use cases, especially with its unparalleled performance and well-tested C++ code base. 
  • Caffe2 is an improvement over the original Caffe framework in a number of features.
  • It has got a steep learning curve to understand and to start coding examples using the framework.

scikit-learn

  • Scikit-learn is one of the best known machine learning package and provides efficient implementation versions of a large number of common machine learning algorithms.
  • It is NOT a mobile machine learning package. However, models created using scikit-learn can be converted to Core ML and TensorFlow Lite models using conversion tools, and used in mobile applications directly.
  • It has got similar and uniform API implementations across machine learning algorithms and very comprehensive supportive documentation.
  • It is very easy to learn scikit-learn and implement and extend models using it.
  • Scikit-learn was initially developed by David Cournapeau as a Google Summer of Code project in 2007. Later, Matthieu Brucher joined the project and started to use it as part of his thesis work. In 2010, INRIA got involved and the first public release (v 0.1 beta) was published in late January 2010. The project now has more than 30 active contributors and has had paid sponsorship from INRIA, Google, Tinyclues, and the Python Software Foundation.
  • Scikit-learn provides a range of supervised and unsupervised learning algorithms via a consistent interface in Python. 
  • It is licensed under a permissive simplified BSD license and is distributed under many Linux distributions, encouraging academic and commercial use.
  • The library is built upon SciPy, which must be installed before you can use scikit-learn.

TensorFlow

  • TensorFlow is an open source library for fast numerical computing. It was created and is maintained by Google, and released under the Apache 2.0 open source license. The API is in the Python programming language, although there is access to the underlying C++ API.
  • There is a separate flavor for mobile, which we already went through in detail and used in our practical hands-on exercises in this book.
  • Models created in TensorFlow can be used and converted to models for TensorFlow for mobile and TensorFlow Lite, and used in mobile applications.
  • TensorFlow was designed for use both in research and development and in production systems. It can run on single CPU systems and GPUs, as well as mobile devices and large-scale distributed systems of hundreds of machines.
  • Mathematically, a tensor is an n-dimensional vector. It can be used to represent n-dimensional datasets. Flow refers to a graph; the graph can never be cyclic and each node in the graph represents an operation such as addition, subtraction, and so on. And each operation results in the formation of a new tensor.
  • Tensor flow enables the evaluation of each node in parallel and not hence the idle waster time waiting for a node evaluation like in serial mode is eliminated by TensorFlow.
  • TensorFlow allows users to make use of parallel computing devices to perform operations faster. 

Core ML

  • Apple released Core ML at WWDC'17, and it was updated to Core ML 2 this year. As a reminder, Core ML enables developers to integrate machine learning models into iOS and MacOS apps. This was the first big attempt in this field, and initially developers really liked it for several reasons.
  • Core ML supports a variety of machine learning models, including neural networks, tree ensembles, support vector machines, and generalized linear models. Core ML requires the Core ML model format (models with a .mlmodel file extension).
  • Apple also provides converters to convert the models created in several other libraries to Core ML format. As we have used these converters in this book, we find that these converters are extremely simple to use and work with most famous existing machine learning libraries.
  • Apple also provides several popular, open source models that are already in the Core ML model format, which can be directly downloaded and used in building our applications.
  • Core ML is optimized for on-device performance, which minimizes memory footprint and power consumption. Running strictly on the device also ensures that user data is kept secure, and the app runs even in the absence of a network connection.
  • Core ML's biggest advantage is that it is extremely simple to use. Just a few lines of code can help you integrate a complete machine learning model. Since the release of Core ML, there has been a flood of innovative projects using it. However, there are limitations around what Core ML can do.
  • Core ML can only help you integrate pre-trained ML models into your app. So, this means you can do predictions only; no model training is possible.
  • Thus far, Core ML has proved to be extremely useful for developers. Core ML 2, which was announced at WWDC this year, should improve inference time by 30% using techniques called quantization and batch prediction.

Mobile machine learning project implementation

In this section, we will go through the basic questions that any machine learning project implementer would have in mind before embarking on the project.

What are the high-level important items to be considered before starting the project?

The following are the high-level items that need to be addressed before starting the project:

  • Clear definition of problem as per the ML definition we have seen, with clear inputs for task T, performance measure P, and experience E
  • Data availability with the required volume
  • Design decision for on-mobile or cloud-based mobile machine learning framework
  • Proper selection of machine learning framework that suits our requirements

What are the roles and skills required to implement a mobile machine learning project?

The following skills and roles can be planned for the mobile machine learning project:

  • Domain expert/specialist: Provides input on problem, data, features in data, business context, and so on
  • Machine learning data scientist: Analyzes the data, does feature engineering and data preprocessing, and builds the machine learning model
  • Mobile application developer: Utilizes the mobile machine learning model to build the mobile application
  • Tester: Tests the model as well as the mobile application 

Here, each role can be learned by others through this book and can be performed by single or multiple people for successful implementation of the mobile machine learning project.

 What should you focus on when testing the mobile machine learning project?

The key thing to be tested in the project is the mobile machine learning model. So, independent of the mobile application, the model needs to be tested thoroughly. 

We have already seen what things should be focused on while testing the machine learning model. The training data, test data, and cross-validation need to be considered while testing the model. The performance measure of the chosen model to be measured. For each run of the clear record keeping of the results to be done, so that we clearly know for a delta change in feature set of the input data, what is the delta change in output. All the concepts explained in Chapter 1Introduction to Machine Learning on Mobile, related to accuracy, precision, recall, error, and so on should be understood clearly by an engineer testing machine learning models. Also, for each type of algorithm, the error and performance measure metrics vary, which should be taken into due consideration while testing the models. Testing machine learning models is itself worth a book and dwelling on the details in this book is out of scope.

What is the help that the domain expert will provide to the machine learning project?

The domain expert/specialist is a key role for the success of any machine learning project and his specific value will be in the following areas:

  • Definition of problem statement and help in correctly understanding the expectations of the solution
  • Data preparation:
    • What are good candidates to be selected in feature engineering and kept as predictor attributes?
    • How to combine multiple objectives/attributes that would help solve the problem statement
    • How to sample to select the test set and training set
    • Help in data cleaning
  • Progress monitoring and result interpretation:
    • Defining the accuracy of prediction required
    • Determining if more data/additional data is required, based on the progress made
    • Making a checkpoint in between and determine if the progress made is in alignment with the problem statement defined and the solution pursued is in line and can be further pursued in same lines or there is need to take a different path/re calibrate methods
  • Continuous update and feedback on progress

What are the common pitfalls in machine learning projects?

The following are some of the common pitfalls seen in any machine learning project:

  • Unrealistic objectives, unclear problem definition with no proper objectives
  • Data problems:
    • Insufficient data to establish predictive patterns
    • Incorrect selection of predictor attributes
    • Data preparation problems
    • Data normalization problems—failure to normalize data across datasets
    • Bias in data use to solve the problem
  • Inappropriate machine learning method selection:
    • The ML method selected doesn't suit the problem statement defined
    • Not trying alternative algorithms
  • Giving up too soon. This happens very often. Engineers tend to lose interest if they don't see initial results and are unable to do the various permutations and combinations of various dependent factors, and also do systematic book keeping for the results. If pursued continuously/methodically with proper record keeping and trying out the various possibilities, machine learning problems can be easily solved.

Installation

In this section, we will go through the different installation procedures required for setting up the tools and SDKs used to create the programs in this book.

Python

In this book, we worked with Python to create the ML models. So, you must know how to install Python in your system to go through the practical examples.

Go to https://www.python.org/downloads/.

It will show you the latest version to download; download the installer and install it.

While installing in Windows, it will ask whether to add Python to the path environment variable. Check the box to do that automatically for yours. Otherwise, you need to add it to your path variable manually.

To check whether Python is installed on your machine or not, go to Command Prompt or a Terminal and type python. It should show the Python prompt. Otherwise, you need to set the path variable if you already installed it to your drive.

Python dependencies

Python will come with the pip package manager by default. You can install using pip. The syntax is as follows:

pip install package name

For more information on available packages, you can visit https://pypi.org/project/pip/. In this book, we have given all the dependency installation commands in their respective chapters.

Xcode

First, create a developer account in Apple and log in to your account at https://developer.apple.com/. Click on Downloads and scroll down/search for the latest Xcode, above 9.4, and then click it to download. It will download the XZIP file. Extract it and install in your Mac machine by dragging it into your applications folder.

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Machine Learning for Mobile
Published in: Dec 2018Publisher: PacktISBN-13: 9781788629355

Authors (2)

author image
Revathi Gopalakrishnan

Revathi Gopalakrishnan is a software professional with more than 17 years of experience in the IT industry. She has worked extensively in mobile application development and has played various roles, including developer and architect, and has led various enterprise mobile enablement initiatives for large organizations. She has also worked on a host of consumer applications for various customers around the globe. She has an interest in emerging areas, and machine learning is one of them. Through this book, she has tried to bring out how machine learning can make mobile application development more interesting and super cool. Revathi resides in Chennai and enjoys her weekends with her husband and her two lovely daughters.
Read more about Revathi Gopalakrishnan

author image
Avinash Venkateswarlu

Avinash Venkateswarlu has more than 3 years' experience in IT and is currently exploring mobile machine learning. He has worked in enterprise mobile enablement projects and is interested in emerging technologies such as mobile machine learning and cryptocurrency. Venkateswarlu works in Chennai, but enjoys spending his weekends in his home town, Nellore. He likes to do farming or yoga when he is not in front of his laptop exploring emerging technologies.
Read more about Avinash Venkateswarlu