Table Of ContentDeep Learning: Practical
Neural Networks with Java
Build and run intelligent applications by leveraging
key Java machine learning libraries
A course in three modules
BIRMINGHAM - MUMBAI
Deep Learning: Practical Neural Networks with Java
Copyright © 2017 Packt Publishing
Published on: May 2017
Production reference: 1310517
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78847-031-5
www.packtpub.com
Preface
Deep Learning algorithms are being used across a broad range of industries – as
the fundamental driver of AI. Machine learning applications are everywhere, from
self-driving cars, spam detection, document search, and trading strategies, to speech
recognition. This makes machine learning well-suited to the present-day era of Big
Data and Data Science. The main challenge is how to transform data into actionable
knowledge.
Starting with an introduction to basic machine learning algorithms, to give you a
solid foundation, Deep Learning with Java takes you further into this vital world of
stunning predictive insights and remarkable machine intelligence. You will learn
how to use Java machine learning libraries and apply Deep Learning to a range
of real-world use cases. Featuring further guidance and insights to help you solve
challenging problems in image processing, speech recognition, language modeling,
you will learn the techniques and tools you need to quickly gain insight from
complex data. You will apply machine learning methods to a variety of common
tasks including classification, prediction, forecasting, market basket analysis, and
clustering. Moving on, you will discover how to detect anomalies and fraud, and
ways to perform activity recognition, image recognition, and text Later you will
focus on what Perceptrons are and their features. You will implement self-organizing
maps using practical examples. Further on, you will work with the examples
such as weather forecasting, disease diagnosis, customer profiling, generalization,
extreme machine learning and more. Finally, you will learn methods to optimize
and adapt neural networks in real time. By the end of this course, you will have all
the knowledge you need to perform deep learning on your system with varying
complexity levels, to apply them to your daily work.
What this learning path covers
Module 1, Java Deep Learning Essentials, takes you further into this vital world of
stunning predictive insights and remarkable machine intelligence. Once you've
got to grips with the fundamental mathematical principles, you'll start exploring
neural networks and identify how to tackle challenges in large networks using
advanced algorithms.
Module 2, Machine Learning in Java, will provide you with the techniques and tools
you need to quickly gain insight from complex data. By applying the most effective
machine learning methods to real-world problems, you will gain hands-on experience
that will transform the way you think about data.
Module 3, Neural Network Programming with Java, Second Edition, takes you on a
complete walkthrough of the process of developing basic to advanced practical
examples based on neural networks with Java, giving you everything you need to
stand out. You will learn methods to optimize and adapt neural networks in real time.
What you need for this learning path
Module 1:
We'll implement deep learning algorithms using Lambda Expressions, hence Java 8
or above is required. Also, we'll use the Java library, DeepLearning4J 0.4 or above.
Module 2:
You'll need Netbeans (www.netbeans.org) or Eclipse (www.eclipse.org). Both are
free and available for download at the previously mentioned websites.
Module 3:
You'll need Netbeans (www.netbeans.org) or Eclipse (www.eclipse.org). Both are
free and available for download at the previously mentioned websites.
Who this learning path is for
This course is intended for data scientists and Java developers who want to dive
into the exciting world of deep learning. It will get you up and running quickly and
provide you with the skills you need to successfully create, customize, and deploy
machine learning applications in real life.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this course—what you liked or disliked. Reader feedback is important for us as it
helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail feedback@packtpub.com, and mention
the course's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt course, we have a number of things
to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for this course from your account at
http://www.packtpub.com. If you purchased this course elsewhere, you can visit
http://www.packtpub.com/support and register to have the files e-mailed directly
to you.
You can download the code files by following these steps:
1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the course in the Search box.
5. Select the course for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this course from.
7. Click on Code Download.
You can also download the code files by clicking on the Code Files button on the
course's webpage at the Packt Publishing website. This page can be accessed by
entering the course's name in the Search box. Please note that you need to be logged
in to your Packt account.
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 course is also hosted on GitHub at https://github.com/
PacktPublishing/Java-Practical-Deep-Learning. We also have other
code bundles from our rich catalog of books, videos, and courses available
at https://github.com/PacktPublishing/. Check them out!
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our courses—maybe a mistake in the text
or the code—we would be grateful if you could report this to us. By doing so, you
can save other readers from frustration and help us improve subsequent versions
of this course. If you find any errata, please report them by visiting http://www.
packtpub.com/submit-errata, selecting your course, clicking on the Errata
Submission Form link, and entering the details of your errata. Once your errata are
verified, your submission will be accepted and the errata will be uploaded to our
website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/
content/support and enter the name of the course in the search field. The required
information will appear under the Errata section.
Module 1: Java Deep Learning Essentials
Chapter 1: Deep Learning Overview 3
Transition of AI 4
Things dividing a machine and human 15
AI and deep learning 16
Summary 24
Chapter 2: Algorithms for Machine Learning – Preparing for
Deep Learning 25
Getting started 25
The need for training in machine learning 26
Supervised and unsupervised learning 29
Machine learning application flow 36
Theories and algorithms of neural networks 42
Summary 68
Chapter 3: Deep Belief Nets and Stacked Denoising Autoencoders 69
Neural networks fall 69
Neural networks' revenge 70
Deep learning algorithms 78
Summary 107
Chapter 4: Dropout and Convolutional Neural Networks 109
Deep learning algorithms without pre-training 109
Dropout 110
Convolutional neural networks 122
Summary 144
i
Table of Contents
Chapter 5: Exploring Java Deep Learning Libraries – DL4J, ND4J,
and More 145
Implementing from scratch versus a library/framework 146
Introducing DL4J and ND4J 148
Implementations with ND4J 150
Implementations with DL4J 156
Summary 177
Chapter 6: Approaches to Practical Applications – Recurrent Neural
Networks and More 179
Fields where deep learning is active 180
The difficulties of deep learning 198
The approaches to maximizing deep learning possibilities and abilities 200
Summary 208
Chapter 7: Other Important Deep Learning Libraries 209
Theano 209
TensorFlow 214
Caffe 219
Summary 222
Chapter 8: What's Next? 223
Breaking news about deep learning 223
Expected next actions 226
Useful news sources for deep learning 231
Summary 234
Module 2: Machine Learning in Java
Chapter 1: Applied Machine Learning Quick Start 237
Machine learning and data science 237
Data and problem definition 240
Data collection 242
Data pre-processing 245
Unsupervised learning 249
Supervised learning 253
Generalization and evaluation 260
Summary 263
ii
Table of Contents
Chapter 2: Java Libraries and Platforms for Machine Learning 265
The need for Java 266
Machine learning libraries 266
Building a machine learning application 278
Summary 280
Chapter 3: Basic Algorithms – Classification, Regression,
and Clustering 281
Before you start 282
Classification 282
Regression 292
Clustering 299
Summary 302
Chapter 4: Customer Relationship Prediction with Ensembles 303
Customer relationship database 304
Basic naive Bayes classifier baseline 307
Basic modeling 311
Advanced modeling with ensembles 313
Summary 322
Chapter 5: Affinity Analysis 323
Market basket analysis 323
Association rule learning 326
The supermarket dataset 330
Discover patterns 330
Other applications in various areas 333
Summary 335
Chapter 6: Recommendation Engine with Apache Mahout 337
Basic concepts 337
Getting Apache Mahout 341
Building a recommendation engine 344
Content-based filtering 359
Summary 360
Chapter 7: Fraud and Anomaly Detection 361
Suspicious and anomalous behavior detection 362
Suspicious pattern detection 363
Anomalous pattern detection 364
Fraud detection of insurance claims 365
Anomaly detection in website traffic 373
Summary 380
iii
Table of Contents
Chapter 8: Image Recognition with Deeplearning4j 381
Introducing image recognition 381
Image classification 389
Summary 399
Chapter 9: Activity Recognition with Mobile Phone Sensors 401
Introducing activity recognition 402
Collecting data from a mobile phone 406
Building a classifier 414
Summary 420
Chapter 10: Text Mining with Mallet – Topic Modeling and
Spam Detection 421
Introducing text mining 421
Installing Mallet 424
Working with text data 426
Topic modeling for BBC news 432
E-mail spam detection 439
Summary 444
Chapter 11: What is Next? 445
Machine learning in real life 445
Standards and markup languages 449
Machine learning in the cloud 451
Web resources and competitions 453
Summary 456
Appendix: References 457
Module 3: Neural Network Programming with Java,
Second Edition
Chapter 1: Getting Started with Neural Networks 463
Discovering neural networks 463
Why artificial neural networks? 464
From ignorance to knowledge – learning process 472
Let the coding begin! Neural networks in practice 473
The neuron class 475
The NeuralLayer class 477
The ActivationFunction interface 478
The neural network class 479
iv
Description:About This Book Develop a sound strategy to solve predictive modelling problems using the most popular machine learning Java libraries. Explore a broad variety of data processing, machine learning, and natural language processing through diagrams, source code, and real-world applications This step-b