About the Book
New experiences can be intimidating, but not this one! This beginner's guide to deep learning is here to help you explore deep learning from scratch with Keras, and be on your way to training your first ever neural networks.
What sets Keras apart from other deep learning frameworks is its simplicity. With over two hundred thousand users, Keras has a stronger adoption in industry and the research community than any other deep learning framework.
The Deep Learning with Keras Workshop starts by introducing you to the fundamental concepts of machine learning using the scikit-learn package. After learning how to perform the linear transformations that are necessary for building neural networks, you'll build your first neural network with the Keras library. As you advance, you'll learn how to build multi-layer neural networks and recognize when your model is underfitting or overfitting to the training data. With the help of practical exercises, you'll learn to use cross-validation techniques to evaluate your models and then choose the optimal hyperparameters to fine tune their performance. Finally, you'll explore recurrent neural networks and learn how to train them to predict values in sequential data.
By the end of this book, you'll have developed the skills you need to confidently train your own neural network models.
Audience
If you know the basics of data science and machine learning and want to get started with advanced machine learning technologies like artificial neural networks and deep learning, then this is the book for you. To grasp the concepts explained in this deep learning book more effectively, prior experience in Python programming and some familiarity with statistics and logistic regression are a must.
About the Chapters
Chapter 1, Introduction to Machine Learning with Keras, will introduce you to the fundamental concepts of machine learning by using the scikit-learn package. You will learn how to present data for model building, then train a logistic regression model using a real-world dataset.
Chapter 2, Machine Learning versus Deep Learning, will present the difference between traditional machine learning algorithms and deep learning algorithms. You will learn the linear transformations necessary for building neural networks and build your first neural network with the Keras library.
Chapter 3, Deep Learning with Keras, will extend your knowledge of neural network building. You will learn how to build multi-layer neural networks and recognize when your model is underfitting or overfitting to the training data.
Chapter 4, Evaluating Your Model with Cross-Validation Using Keras Wrappers, will teach you how to use Keras wrappers with scikit-learn to incorporate Keras models into a scikit-learn workflow. You will apply cross-validation to evaluate your models and use this technique to choose the optimal hyperparameters.
Chapter 5, Improving Model Accuracy, will introduce various regularization techniques to prevent your models from overfitting to the training data. You will learn different methods to search for the optimal hyperparameters that result in the highest model accuracy.
Chapter 6, Model Evaluation, will demonstrate a variety of methods to evaluate your models. Beyond accuracy, you will learn more model evaluation metrics including sensitivity, specificity, precision, false positive rate, ROC curves, and AUC scores to understand how well your models perform.
Chapter 7, Computer Vision with Convolutional Neural Networks, will introduce you to building image classifiers with convolutional neural networks. You will learn about all the components that comprise the architecture of convolutional neural networks and then build image processing applications to classify images.
Chapter 8, Transfer Learning and Pre-Trained Models, will introduce you to the concept of transferring the learning from one model to solve for other applications. You will achieve this by using different pre-trained models and modifying them slightly to fit different applications.
Chapter 9, Sequential Modeling with Recurrent Neural Networks, will teach you how to build models with sequential data. You will learn the architecture of recurrent neural networks and how to train them to predict the succeeding values from sequential data. You will test your knowledge by predicting the future values of various stock prices.
Conventions
Code words in text, database table names, folder names, filenames, file extensions, path names, dummy URLs, user input, and Twitter handles are shown as follows:
"sklearn
has a class called train_test_split
, which provides the functionality for splitting data."
Words that you see on the screen, for example, in menus or dialog boxes, also appear in the same format.
A block of code is set as follows:
# import libraries import pandas as pd from sklearn.model_selection import train_test_split
New terms and important words are shown like this:
"A dictionary contains multiple elements, like a list, but each element is organized as a key-value pair."
Code Presentation
Lines of code that span multiple lines are split using a backslash ( \
). When the code is executed, Python will ignore the backslash, and treat the code on the next line as a direct continuation of the current line.
For example:
history = model.fit(X, y, epochs=100, batch_size=5, verbose=1, \ validation_split=0.2, shuffle=False)
Comments are added into code to help explain specific bits of logic. Single-line comments are denoted using the #
symbol, as follows:
# Print the sizes of the dataset print("Number of Examples in the Dataset = ", X.shape[0]) print("Number of Features for each example = ", X.shape[1])
Multi-line comments are enclosed by triple quotes, as shown below:
""" Define a seed for the random number generator to ensure the result will be reproducible """ seed = 1 np.random.seed(seed) random.set_seed(seed)
Setting up Your Environment
Before we explore the book in detail, we need to set up specific software and tools. In the following section, we shall see how to do that.
Installing Anaconda
For this course, we will use Anaconda; a Python distribution which comes with an in-built package manager and pre-installed packages frequently used for machine learning and scientific computing,
To install Anaconda, find your desired version (Windows, macOS, or Linux) on the official installation page at https://docs.anaconda.com/anaconda/install/. Follow the appropriate installation instructions for your operating system.
Once Anaconda is installed, you can interact with it via the Anaconda Navigator or Anaconda Prompt. There are instructions on how to use these at https://docs.anaconda.com/anaconda/user-guide/getting-started/.
To verify the correct installation, you can execute the anaconda-navigator
command on CMD / Terminal. If the installation is correct, this will open up the Anaconda Navigator.
Installing Libraries
pip
comes pre-installed with Anaconda. Once Anaconda is installed on your machine, all the required libraries can be installed using pip
, for example, pip install numpy
. Alternatively, you can install all the required libraries using pip install –r requirements.txt
. You can find the requirements.txt
file at https://packt.live/3hhZ2v9.
The exercises and activities will be executed in Jupyter Notebooks. Jupyter is a Python library and can be installed in the same way as the other Python libraries – that is, with pip install jupyter
, but fortunately, it comes pre-installed with Anaconda.
Running Jupyter Notebook
You can start Jupyter via the appropriate link in the Anaconda Navigator, or by executing the command jupyter notebook
in Anaconda Prompt / CMD / Terminal.
Jupyter will open up in your browser, where you will then be able to navigate to your working directory and create, edit and run your code files.
Accessing the Code Files
You can find the complete code files of this book at https://packt.live/2OL5E9t. You can also run many activities and exercises directly in your web browser by using the interactive lab environment at https://packt.live/2CXyFLS.
We've tried to support interactive versions of all activities and exercises, but we recommend a local installation as well for instances where this support isn't available.
The high-quality color images used in the book can found at https://packt.live/2u9Tno4.
If you have any issues or questions about installation, please email us at [email protected]
.