Reader small image

You're reading from  Hands-On Machine Learning on Google Cloud Platform

Product typeBook
Published inApr 2018
PublisherPackt
ISBN-139781788393485
Edition1st Edition
Right arrow
Authors (3):
Giuseppe Ciaburro
Giuseppe Ciaburro
author image
Giuseppe Ciaburro

Giuseppe Ciaburro holds a PhD and two master's degrees. He works at the Built Environment Control Laboratory - Università degli Studi della Campania "Luigi Vanvitelli". He has over 25 years of work experience in programming, first in the field of combustion and then in acoustics and noise control. His core programming knowledge is in MATLAB, Python and R. As an expert in AI applications to acoustics and noise control problems, Giuseppe has wide experience in researching and teaching. He has several publications to his credit: monographs, scientific journals, and thematic conferences. He was recently included in the world's top 2% scientists list by Stanford University (2022).
Read more about Giuseppe Ciaburro

V Kishore Ayyadevara
V Kishore Ayyadevara
author image
V Kishore Ayyadevara

V Kishore Ayyadevara leads a team focused on using AI to solve problems in the healthcare space. He has 10 years' experience in data science, solving problems to improve customer experience in leading technology companies. In his current role, he is responsible for developing a variety of cutting edge analytical solutions that have an impact at scale while building strong technical teams. Prior to this, Kishore authored three books — Pro Machine Learning Algorithms, Hands-on Machine Learning with Google Cloud Platform, and SciPy Recipes. Kishore is an active learner with keen interest in identifying problems that can be solved using data, simplifying the complexity and in transferring techniques across domains to achieve quantifiable results.
Read more about V Kishore Ayyadevara

Alexis Perrier
Alexis Perrier
author image
Alexis Perrier

Alexis Perrier is a data science consultant with experience in signal processing and stochastic algorithms. He holds a master's in mathematics from Universit Pierre et Marie Curie Paris VI and a PhD in signal processing from Tlcom ParisTech. He is actively involved in the DC data science community. He is also an avid book lover and proud owner of a real chalk blackboard, where he regularly shares his fascination of mathematical equations with his kids.
Read more about Alexis Perrier

View More author details
Right arrow

Optimizing the Model through Hyperparameter Tuning

Neural networks constitute multiple parameters that can affect the ultimate accuracy in predicting an event or a label. The typical parameters include:

  • Batch size used for training
  • Number of epochs
  • Learning rate
  • Number of hidden layers
  • Number of hidden units in each hidden layer
  • The activation function applied in the hidden layer
  • The optimizer used

From the preceding list, we can see that the number of parameters that can be tweaked is very high. This makes finding the optimal combination of hyperparameters a challenge. Hyperparameter tuning as a service provided by Cloud ML Engine comes in handy in such a scenario.

In this chapter, we will go through:

  • Why hyperparameter tuning is required
  • An overview of how hyperparameter tuning works
  • Implementing hyperparameter tuning in the cloud
...

The intuition of hyperparameter tuning

In order to gain a practical intuition of the need for hyperparameter tuning, let's go through the following scenario in predicting the accuracy of a given neural network architecture on the MNIST dataset:

  • Scenario 1: High number of epochs and low learning rate
  • Scenario 2: Low number of epochs and high learning rate

Let us create the train and test datasets in a Google Cloud environment, as follows:

  1. Download the dataset:
mkdir data
curl -O https://s3.amazonaws.com/img-datasets/mnist.pkl.gz
gzip -d mnist.pkl.gz
mv mnist.pkl data/            

The preceding code creates a new folder named data, downloads the MNIST dataset, and moves it into the data folder.

  1. Open Python in Terminal and import the required packages:
from __future__ import print_function 
import tensorflow as tf
import pickle # for handling the new data source
import numpy...

Summary

In this chapter, we understood how different parameter combinations affect the final accuracy measure and how hyperparameter tuning using Cloud ML engine helps in improving the accuracy further.

In the next chapter, we will learn how to identify overfitting and make our models more robust to previously-unseen data by setting the right parameters and defining the proper architectures.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Machine Learning on Google Cloud Platform
Published in: Apr 2018Publisher: PacktISBN-13: 9781788393485
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Giuseppe Ciaburro

Giuseppe Ciaburro holds a PhD and two master's degrees. He works at the Built Environment Control Laboratory - Università degli Studi della Campania "Luigi Vanvitelli". He has over 25 years of work experience in programming, first in the field of combustion and then in acoustics and noise control. His core programming knowledge is in MATLAB, Python and R. As an expert in AI applications to acoustics and noise control problems, Giuseppe has wide experience in researching and teaching. He has several publications to his credit: monographs, scientific journals, and thematic conferences. He was recently included in the world's top 2% scientists list by Stanford University (2022).
Read more about Giuseppe Ciaburro

author image
V Kishore Ayyadevara

V Kishore Ayyadevara leads a team focused on using AI to solve problems in the healthcare space. He has 10 years' experience in data science, solving problems to improve customer experience in leading technology companies. In his current role, he is responsible for developing a variety of cutting edge analytical solutions that have an impact at scale while building strong technical teams. Prior to this, Kishore authored three books — Pro Machine Learning Algorithms, Hands-on Machine Learning with Google Cloud Platform, and SciPy Recipes. Kishore is an active learner with keen interest in identifying problems that can be solved using data, simplifying the complexity and in transferring techniques across domains to achieve quantifiable results.
Read more about V Kishore Ayyadevara

author image
Alexis Perrier

Alexis Perrier is a data science consultant with experience in signal processing and stochastic algorithms. He holds a master's in mathematics from Universit Pierre et Marie Curie Paris VI and a PhD in signal processing from Tlcom ParisTech. He is actively involved in the DC data science community. He is also an avid book lover and proud owner of a real chalk blackboard, where he regularly shares his fascination of mathematical equations with his kids.
Read more about Alexis Perrier