Machine Learning for iOS Developers - Abhishek Mishra - E-Book

Machine Learning for iOS Developers E-Book

Abhishek Mishra

0,0
32,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Harness the power of Apple iOS machine learning (ML) capabilities and learn the concepts and techniques necessary to be a successful Apple iOS machine learning practitioner! Machine earning (ML) is the science of getting computers to act without being explicitly programmed. A branch of Artificial Intelligence (AI), machine learning techniques offer ways to identify trends, forecast behavior, and make recommendations. The Apple iOS Software Development Kit (SDK) allows developers to integrate ML services, such as speech recognition and language translation, into mobile devices, most of which can be used in multi-cloud settings. Focusing on Apple's ML services, Machine Learning for iOS Developers is an up-to-date introduction to the field, instructing readers to implement machine learning in iOS applications. Assuming no prior experience with machine learning, this reader-friendly guide offers expert instruction and practical examples of ML integration in iOS. Organized into two sections, the book's clearly-written chapters first cover fundamental ML concepts, the different types of ML systems, their practical uses, and the potential challenges of ML solutions. The second section teaches readers to use models--both pre-trained and user-built--with Apple's CoreML framework. Source code examples are provided for readers to download and use in their own projects. This book helps readers: * Understand the theoretical concepts and practical applications of machine learning used in predictive data analytics * Build, deploy, and maintain ML systems for tasks such as model validation, optimization, scalability, and real-time streaming * Develop skills in data acquisition and modeling, classification, and regression. * Compare traditional vs. ML approaches, and machine learning on handsets vs. machine learning as a service (MLaaS) * Implement decision tree based models, an instance-based machine learning system, and integrate Scikit-learn & Keras models with CoreML Machine Learning for iOS Developers is a must-have resource software engineers and mobile solutions architects wishing to learn ML concepts and implement machine learning on iOS Apps.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 459

Veröffentlichungsjahr: 2020

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Cover

Introduction

What Does This Book Cover?

Additional Resources

Reader Support for This Book

Part 1: Fundamentals of Machine Learning

Chapter 1: Introduction to Machine Learning

What Is Machine Learning?

Types of Machine Learning Systems

Common Machine Learning Algorithms

Sources of Machine Learning Datasets

Summary

Chapter 2: The Machine-Learning Approach

The Traditional Rule-Based Approach

A Machine-Learning System

The Machine-Learning Process

Summary

Chapter 3: Data Exploration and Preprocessing

Data Preprocessing Techniques

Selecting Training Features

Summary

Chapter 4: Implementing Machine Learning on Mobile Apps

Device-Based vs. Server-Based Approaches

Apple's Machine Learning Frameworks and Tools

Third-Party Machine-Learning Frameworks and Tools

Summary

Part 2: Machine Learning with CoreML, CreateML, and TuriCreate

Chapter 5: Object Detection Using Pre-trained Models

What Is Object Detection?

A Brief Introduction to Artificial Neural Networks

Downloading the ResNet50 Model

Creating the iOS Project

Summary

Chapter 6: Creating an Image Classifier with the Create ML App

Introduction to the Create ML App

Creating the Image Classification Model with the Create ML App

Creating the iOS Project

Summary

Chapter 7: Creating a Tabular Classifier with Create ML

Preparing the Dataset for the Create ML App

Creating the Tabular Classification Model with the Create ML App

Creating the iOS Project

Summary

Chapter 8: Creating a Decision Tree Classifier

Decision Tree Recap

Examining the Dataset

Creating Training and Test Datasets

Creating the Decision Tree Classification Model with Scikit-learn

Using Core ML Tools to Convert the Scikit-learn Model to the Core ML Format

Creating the iOS Project

Summary

Chapter 9: Creating a Logistic Regression Model Using Scikit-learn and Core ML

Examining the Dataset

Creating a Training and Test Dataset

Creating the Logistic Regression Model with Scikit-learn

Using Core ML Tools to Convert the Scikit-learn Model to the Core ML Format

Creating the iOS Project

Summary

Chapter 10: Building a Deep Convolutional Neural Network with Keras

Introduction to the Inception Family of Deep Convolutional Neural Networks

A Brief Introduction to Keras

Implementing Inception-v4 with the Keras Functional API

Training the Inception-v4 Model

Exporting the Keras Inception-v4 Model to the Core ML Format

Creating the iOS Project

Summary

Appendix A: Anaconda and Jupyter Notebook Setup

Installing the Anaconda Distribution

Creating a Conda Python Environment

Installing Python Packages

Installing Jupyter Notebook

Summary

Appendix B: Introduction to NumPy and Pandas

NumPy

Pandas

Summary

Index

End User License Agreement

List of Tables

Chapter 1

TABLE 1.1: Type and Range of Data Across 100 Sample Application

Chapter 2

TABLE 2.1: Type and Range of Data Across 5,000 Sample Applications

TABLE 2.2: Transforming Categorical Features Into Numeric Features

TABLE 2.3: Modified Input Features

Chapter 4

TABLE 4.1: Pros and Cons of Server-Side and Edge-Based Deployment

Chapter 7

TABLE 7.1: Minimum and Maximum Values of the Features of the UCI ML Wine Dataset

Appendix B

Table B.1: Commonly Used ndarray Attributes

List of Illustrations

Chapter 1

FIGURE 1.1 Supervised learning

FIGURE 1.2 Clustering technique used to find patterns in the data

FIGURE 1.3 Semisupervised learning

FIGURE 1.4 A simple linear regression model

FIGURE 1.5 Three potential decision boundaries

FIGURE 1.6 Data that cannot be classified using a linear decision boundary i...

FIGURE 1.7 Data that cannot be classified using a linear decision boundary i...

FIGURE 1.8 Nonlinear decision boundary in two-dimensional space

FIGURE 1.9 The sigmoid function

FIGURE 1.10 Using the sigmoid function for binary classification

FIGURE 1.11 Softmax logistic regression

FIGURE 1.12 Decision tree visualization

FIGURE 1.13 Structure of an ANN

FIGURE 1.14 A simple neural network

Chapter 2

FIGURE 2.1 Architecture of a rule-based decision system

FIGURE 2.2 A flowchart depicting the decision-making process for a rule-base...

FIGURE 2.3 Cross-validation using four folds

FIGURE 2.4 Using the sigmoid function for binary classification

FIGURE 2.5 A class-wise confusion matrix

FIGURE 2.6 ROC curves for two binary classification models

Chapter 3

FIGURE 3.1 The

head()

function displays rows from the beginning of a Pandas ...

FIGURE 3.2 The

head()

function displays truncated data for large dataframes.

FIGURE 3.3 Impact of the

set_index

function on a dataframe

FIGURE 3.4 Distribution of values for the survived attribute

FIGURE 3.5 Histogram of numeric features

FIGURE 3.6 Histogram of numeric feature

Age

using different widths (2, 3, 5,...

FIGURE 3.7 Histogram of categorical feature, Embarked

FIGURE 3.8 Box plot of numeric features

FIGURE 3.9 Box plot of the

Age

feature variable

FIGURE 3.10 Dataframe with engineered feature

AgeCategory

FIGURE 3.11 Dataframe with engineered feature FareCategory

FIGURE 3.12 Histogram of

Age

,

NormalizedAge

, and

StandardizedAge

FIGURE 3.13 Linear correlation between numeric columns

FIGURE 3.14 Matrix of scatter plots between pairs of numeric attributes

FIGURE 3.15 Variance of data along the x- and y-axes

FIGURE 3.16 Projecting two-dimensional data onto a one-dimensional line

FIGURE 3.17 Features after principal component analysis

Chapter 5

FIGURE 5.1 Object detection techniques applied in industrial inspection

FIGURE 5.2 Object detection stages

FIGURE 5.3 Structure of an artificial neural network

FIGURE 5.4 A simple neural network

FIGURE 5.5 Architecture of a convolutional neural network

FIGURE 5.6 The convolution operation

FIGURE 5.7 The result of successive convolutions

FIGURE 5.8 The effect of max pooling

FIGURE 5.9 A visualization of CNN layers by Adam Harley

FIGURE 5.10 Architecture of VGG16

FIGURE 5.11 A network that uses residual learning

FIGURE 5.12 Pre-trained Core ML models

FIGURE 5.13 Downloading the pre-trained Resnet50 Core ML model

FIGURE 5.14 Creating a new iOS project using the Single View App template

FIGURE 5.15 Application storyboard with default view controller scene

FIGURE 5.16 Using the assistant editor to create outlets

FIGURE 5.17 Editing the application's info.plist file

FIGURE 5.18 Import settings for the Resnet50.mlmodel file

FIGURE 5.19 Overview of the Resnet50.mlmodel file

FIGURE 5.20 Accessing the Swift interface to the Core ML model file

FIGURE 5.21 A section of the Resnet50.Swift file

FIGURE 5.22 VNCoreMLRequest scale and crop options

FIGURE 5.23 Results of running the app with the picture of a flowerpot

Chapter 6

FIGURE 6.1 Launching the Create ML app

FIGURE 6.2 Selecting the Image Classifier template

FIGURE 6.3 Create ML project options dialog

FIGURE 6.4 Specifying the input dataset

FIGURE 6.5 Training data augmentation options

FIGURE 6.6 Beginning the model training process

FIGURE 6.7 Model performance statistics

FIGURE 6.8 Navigating to the test dataset

FIGURE 6.9 Predictions on the test dataset

FIGURE 6.10 Creating a new iOS project using the Single View App template

FIGURE 6.11 Application storyboard with default view controller scene

FIGURE 6.12 Using the Assistant Editor to create outlets

FIGURE 6.13 Editing the application's

Info.plist

file

FIGURE 6.14 Import settings for the DogsCatsTransferLearningClassifier.mlmode...

FIGURE 6.15 Overview of the

DogsCatsTransferLearningClassifier.mlmodel

file

FIGURE 6.16 Accessing the Swift interface to the Core ML model file

FIGURE 6.17 A section of the

DogsCatsTransferLearningClassifier.Swift

file

FIGURE 6.18 Results of running the app with the picture of a dog

Chapter 7

FIGURE 7.1 Creating a new notebook file

FIGURE 7.2 Inspecting the first five rows of the UCI ML wine dataset

FIGURE 7.3 Inspecting the first five rows of the UCI ML wine dataset after c...

FIGURE 7.4 Inspecting the statistical characteristics of the numeric columns...

FIGURE 7.5 Histogram of the data in the target attribute of the Iris dataset

FIGURE 7.6 Inspecting the first five rows of the UCI ML wine dataset after s...

FIGURE 7.7 Launching the Create ML app

FIGURE 7.8 Selecting the Tabular Classifier template

FIGURE 7.9 Create ML project options dialog

FIGURE 7.10 Specifying the input dataset

FIGURE 7.11 Selecting the target attribute

FIGURE 7.12 Accessing the feature selection dialog box

FIGURE 7.13 Selecting the names of the columns of the dataset that represent...

FIGURE 7.14 Specifying the test dataset

FIGURE 7.15 Beginning the model training process

FIGURE 7.16 Beginning the model training process

FIGURE 7.17 Creating a new iOS project using the Single View App template

FIGURE 7.18 Using the Attributes Inspector to change the border style of the...

FIGURE 7.19 Application storyboard with default view controller scene

FIGURE 7.20 Using the assistant editor to create outlets

FIGURE 7.21 Setting up the text field delegate

FIGURE 7.22 Setting up the selector property of the tap gesture recognizer

FIGURE 7.23 Import settings for the

WineClassifier.mlmodel

file

FIGURE 7.24 Overview of the

WineClassifier.mlmodel

file

FIGURE 7.25 Accessing the Swift interface to the Core ML model file

FIGURE 7.26 Results of running the app on the iOS simulator

Chapter 8

FIGURE 8.1 Creating a new notebook file

FIGURE 8.2 Inspecting the first five rows of the Iris flowers dataset

FIGURE 8.3 Histogram of the data in the target attribute of the Iris flowers...

FIGURE 8.4 Inspecting the first five rows of the Iris flowers dataset after ...

FIGURE 8.5 Inspecting the statistical characteristics of the numeric columns...

FIGURE 8.6 Executing the code in all the cells of the Jupyter Notebook

FIGURE 8.7 Graphical representation of the decision tree model

FIGURE 8.8 Creating a new iOS project using the Single View App template

FIGURE 8.9 Using the Attributes Inspector to change the border style of the ...

FIGURE 8.10 Application storyboard with default view controller scene

FIGURE 8.11 Using the Assistant Editor to create outlets

FIGURE 8.12 Setting up the text field delegate

FIGURE 8.13 Setting up the selector property of the tap gesture recognizer

FIGURE 8.14 Import settings for the

iris_dtree.mlmodel

file

FIGURE 8.15 Overview of the

iris_dtree.mlmodel

file

FIGURE 8.16 Accessing the Swift interface to the Core ML model file

FIGURE 8.17 Results of running the app on the iOS simulator

Chapter 9

FIGURE 9.1 Creating a new notebook file

FIGURE 9.2 Inspecting the first five rows of the diabetes dataset

FIGURE 9.3 Inspecting the statistical characteristics of the diabetes datase...

FIGURE 9.4 Histograms of the data in each column of the dataset

FIGURE 9.5 Histograms of the

BMI

,

Glucose

, and

BloodPressure

features

FIGURE 9.6 Distribution of the classes in the target attribute of the origin...

FIGURE 9.7 The Sigmoid function

FIGURE 9.8 Using the Sigmoid function for binary classification

FIGURE 9.9 Creating a new iOS project using the Single View App template

FIGURE 9.10 Using the Attributes Inspector to change the border style of the...

FIGURE 9.11 Application storyboard with default view controller scene

FIGURE 9.12 Using the Assistant Editor to create outlets

FIGURE 9.13 Setting up the text field delegate

FIGURE 9.14 Setting up the selector property of the tap gesture recognizer

FIGURE 9.15 Import settings for the

diabetes_logreg.mlmodel

file

FIGURE 9.16 Overview of the

diabetes_logreg.mlmodel

file

FIGURE 9.17 Accessing the Swift interface to the Core ML model file

FIGURE 9.18 Results of running the app on the iOS simulator

Chapter 10

FIGURE 10.1 A 3×3 convolution operation tiled across a larger image

FIGURE 10.2 An Inception block

FIGURE 10.3 Modified Inception block using 1 x 1 convolutions

FIGURE 10.4 GoogLeNet (Inception-v1) architecture

FIGURE 10.5 Inception-v3 blocks

FIGURE 10.6 Inception-v4 network architecture

FIGURE 10.7 Inception-A, Inception-B, Inception-C blocks

FIGURE 10.8 Structure of the stem of the Inception-v4 network

FIGURE 10.9 Reduction-A and Reduction-B blocks

FIGURE 10.10 Keras' modular architecture

FIGURE 10.11 Creating a new notebook file

FIGURE 10.12 Padding options for convolutional layers

FIGURE 10.13 A one-dimensional strided convolution operation

FIGURE 10.14 Inspecting the first few rows of the

dfTrainingData

dataframe

FIGURE 10.15 A plot of the training history

FIGURE 10.16 Creating a new iOS project using the Single View App template

FIGURE 10.17 Application storyboard with default view controller scene

FIGURE 10.18 Using the Assistant Editor to create outlets

FIGURE 10.19 Editing the application's

Info.plist

file

FIGURE 10.20 Import settings for the Inceptionv4-dogscats.mlmodel file

FIGURE 10.21 Overview of the

Inceptionv4-dogscats.mlmodel

file

FIGURE 10.22 Accessing the Swift interface to the Core ML model file

FIGURE 10.23 A section of the Inceptionv4-dogscats.Swift file

FIGURE 10.24 Results of running the app with the picture of a dog

Appendix A

FIGURE A.1

Anaconda.com

home page

FIGURE A.2 Downloading the appropriate version of Anaconda distribution

FIGURE A.3 Anaconda distribution installer on macOS X

FIGURE A.4 Anaconda installer provides the option to install third-party IDE...

FIGURE A.5 Anaconda has been successfully installed.

FIGURE A.6 Environment settings in Anaconda Navigator

FIGURE A.7 Creating a new Conda Python environment

FIGURE A.8 Switching to the IOS_ML_Book Conda environment

FIGURE A.9 Displaying all available Python packages

FIGURE A.10 Searching for a package

FIGURE A.11 Package dependencies dialog box

FIGURE A.12 Installing Jupyter Notebook

FIGURE A.13 Jupyter Notebook running in a web browser

Guide

Cover

Table of Contents

Begin Reading

Pages

i

xix

xx

xxi

1

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

73

74

75

76

77

78

79

80

81

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

315

316

317

318

319

320

321

322

323

324

325

326

327

iv

v

vii

ix

xi

328

Machine Learning for iOS Developers

 

 

Abhishek Mishra

 

 

 

 

 

 

Introduction

Machine learning is one of the hottest trends in computing and deals with the problem of creating computer programs that can generalize and predict information reliably, quickly, and with accuracy, resembling what a human would do with similar information. With the recent hype in mainstream media around novel applications of machine learning, you may be inclined to think that machine learning is a relatively new discipline, but that is far from the truth. In fact, machine learning has been around for several decades, and it is because of recent advances in storage, processor, and GPU technology that it is possible to build and deploy machine learning systems at scale and get results in real time.

This book is targeted at intermediate/advanced iOS developers who are looking to come to grips with the fundamentals of machine learning, learn about some of the common tools used by data scientists, and learn how to build and deploy models into their iOS applications. This book at all times attempts to balance theory and practice, giving you enough visibility into the underlying concepts while providing you with the best practices and practical advice that you can apply to your workplace right away.

Machine learning is a rapidly evolving field. I have made every attempt to keep the content up-to-date and relevant. Even though this makes the book susceptible to being outdated on a few rare instances, I am confident the content will remain useful and relevant through the next releases of iOS.

What Does This Book Cover?

This book covers the fundamental concepts of machine learning as well as the use of these concepts to build real-world models and use them in your iOS apps.

Chapter 1

: Introduction to Machine Learning

This chapter introduces the different types of machine learning models commonly found in real-world applications as well as tools and libraries used by data scientists to build these models. The chapter also includes examples of real-world applications of machine learning and sources of training data.

Chapter 2

: The Machine-Learning Approach

This chapter examines a hypothetical scenario in which a rule-based system is used to process credit card applications. The limitations of the rule-based system are examined, and a machine learning system is devised to address some of those limitations. The chapter concludes with an overview of the steps involved in building a typical machine learning solution.

Chapter 3

: Data Exploration and Preprocessing

This chapter focuses on the data exploration and feature engineering stage, specifically the use of popular Python libraries NumPy, Pandas, and Scikit-learn for tabular data. The chapter also explores feature selection techniques.

Chapter 4

: Implementing Machine Learning on Mobile Apps

This chapter explores the options available to you as an iOS developer to integrate machine learning techniques on your apps. The chapter compares the pros and cons of an edge-based versus server-based deployment model and introduces both Apple offerings as well as other third-party offerings that can be used from within your apps.

Chapter 5

: Object Detection Using Pre-trained Models

This chapter focuses on the use of pre-trained models for object detection in your iOS apps. The chapter also covers the basics of artificial neural networks (ANNs) and convolutional neural networks (CNNs).

Chapter 6

: Creating an Image Classifier with the Create ML App

This chapter covers the use of Apple's Create ML app to train a machine learning model that can detect the dominant object in an image. The model is trained on a subset of the Kaggle Dogs vs. Cats dataset and exported to the Core ML format. The exported model is used within an iOS app.

Chapter 7

: Creating a Tabular Classifier with Create ML

This chapter covers the use of Apple's Create ML app to train a classification model on tabular data. The model is trained on the popular UCI ML wine dataset and exported to the Core ML format using the Create ML app. The trained model is then used in an iOS app that allows users to input the chemical characteristics of wine and learn the quality of the beverage.

Chapter 8

: Creating a Decision Tree Classifier

This chapter focuses on the use of Scikit-learn to create a decision tree classification model on the popular Iris flowers dataset. The trained model is then exported to the Core ML format using the Core ML Tools Python library and used in an iOS app.

Chapter 9

: Create a Logistic Regression Model Using Scikit-learn and Core ML

This chapter focuses on the use of Scikit-learn to create a logistic regression model on the popular Pima Indians diabetes dataset. The trained model is then exported to the Core ML format using the Core ML Tools Python library and used in an iOS app.

Chapter 10

: Building a Deep Convolutional Neural Network with Keras

This chapter covers the creation and training of a popular deep convolutional neural network architecture called Inception V4 using the Keras functional API. The Inception V4 network is trained on a small publicly available dataset and then used in an iOS app.

Appendix A

: Anaconda and Jupyter Notebook Setup

This appendix helps you install Anaconda Navigator on your computer, set up a Python environment that includes several common machine learning libraries, and configure Jupyter Notebook.

Appendix B

: Introduction to NumPy and Pandas

This appendix shows you how to use NumPy and Pandas. These libraries are commonly used during the data exploration and feature engineering phases of a project.

Additional Resources

In addition to this book, here are some other resources that can help you learn more about machine learning.

Apple Machine Learning Journal:

https://machinelearning.apple.com

Scikit-learn User Guide:

https://scikit-learn.org/stable/user_guide.html

Core ML Developer Documentation:

https://developer.apple.com/documentation/coreml

Core ML Tools Documentation:

https://apple.github.io/coremltools/

Keras Documentation:

https://keras.io

Reader Support for This Book

We provide support for this book in a couple of ways.

Companion Download Files

As you work through the examples in this book, the project files you need are all available for download from www.wiley.com/go/machinelearningforiosdevelopers.

How to Contact the Publisher

If you believe you've found a mistake in this book, please bring it to our attention. At John Wiley & Sons, we understand how important it is to provide our customers with accurate content, but even with our best efforts an error may occur.

To submit your possible errata, please email it to our customer service team at [email protected] with the subject line “Possible Book Errata Submission.”

Part 1Fundamentals of Machine Learning

Chapter 1

:  Introduction to Machine Learning

Chapter 2

:  The Machine-Learning Approach

Chapter 3

:  Data Exploration and Preprocessing

Chapter 4

:  Implementing Machine Learning on Mobile Apps