Reader small image

You're reading from  Mastering Predictive Analytics with scikit-learn and TensorFlow

Product typeBook
Published inSep 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781789617740
Edition1st Edition
Languages
Right arrow
Author (1)
Alvaro Fuentes
Alvaro Fuentes
author image
Alvaro Fuentes

Alvaro Fuentes is a senior data scientist with a background in applied mathematics and economics. He has more than 14 years of experience in various analytical roles and is an analytics consultant at one of the ‘Big Three' global management consulting firms, leading advanced analytics projects in different industries like banking, technology, and consumer goods. Alvaro is also an author and trainer in analytics and data science and has published courses and books, such as 'Become a Python Data Analyst' and 'Hands-On Predictive Analytics with Python'. He has also taught data science and related topics to thousands of students both on-site and online through different platforms such as Springboard, Simplilearn, Udemy, and BSG Institute, among others.
Read more about Alvaro Fuentes

Right arrow

Predictive Analytics with TensorFlow and Deep Neural Networks

TensorFlow is an open source library developed by Google Brain Team. It is used in large-scale machine learning applications, such as neural networks, and for making numerical computations. Developers are able to create dataflow graphs using TensorFlow. These graphs show the movement of data. TensorFlow can be used to train and run deep neural networks for various applications such as image recognition, machine language translation, and natural language processing.

We already know that predictive analytics is about providing predictions about unknown events. We are going to use it here with TensorFlow.

In this chapter, we will cover the following topics:

  • Predictions with TensorFlow
  • Regression with Deep Neural networks (DNNs)
  • Classification with DNNs

Predictions with TensorFlow

We will perform the hello world example of deep learning. This example is used to check and ensure that a model is working as intended. For this, we will use the MNIST dataset.

Introduction to the MNIST dataset

MNIST stands for Mixed National Institute of Standards and Technology, which has produced a handwritten digits dataset. This is one of the most researched datasets in machine learning, and is used to classify handwritten digits. This dataset is helpful for predictive analytics because of its sheer size, allowing deep learning to work its magic efficiently. This dataset contains 60,000 training images and 10,000 testing images, formatted as 28 x 28 pixel monochrome images. The following screenshot...

Regression with Deep Neural Networks (DNN)

For regression with DNNs, we first have to import the libraries we will use here. We will import TensorFlow, pandas, NumPy, and matplotlib with the lines of code shown in the following screenshot:

We will use the fully_ connected function from the tensorflow.contrib.layers model.

Elements of the DNN model

Before running the model, we first have to determine the elements that we will use in building a multilayer perceptron model, shown as follows:

  • Architecture: The model contains 23 elements in the input layer, hence we have 25 features in this dataset. We have only one element in the output layer and we will use three hidden layers, although we could use any number of hidden layers...

Classification with DNNs

For understanding classification with DNNs, we first have to understand the concept of exponential linear unit function and the elements of the model.

Exponential linear unit activation function

The Exponential Linear Unit (ELU) function is a relatively recent modification to the ReLU function. It looks very similar to the ReLU function, but it has very different mathematical properties. The following screenshot shows the ELU function:

The preceding screenshot shows that, at 0, we don't have a corner. In the case of the ReLU function, we have a corner. In this function, instead of a single value going to 0, we have the ELU function slowly going to the negative alpha parameter.

...

Summary

In this chapter, we learned how to make predictions using TensorFlow. We studied the MNIST dataset and classification of models using this dataset. We came across the elements of DNN models and the process of building the DNN. Later, we progressed to study regression and classification with DNNs. We classified handwritten digits and learned more about building models in TensorFlow. This brings us to the end of this book! We learned how to use ensemble algorithms to produce accurate predictions. We applied various techniques to combine and build better models. We learned how to perform cross-validation efficiently. We also implemented various techniques to solve current issues in the domain of predictive analysis. And, the best part, we used the DNN models we built to solve classification and regression problems. This book has helped us implement various machine learning...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Predictive Analytics with scikit-learn and TensorFlow
Published in: Sep 2018Publisher: PacktISBN-13: 9781789617740
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

Author (1)

author image
Alvaro Fuentes

Alvaro Fuentes is a senior data scientist with a background in applied mathematics and economics. He has more than 14 years of experience in various analytical roles and is an analytics consultant at one of the ‘Big Three' global management consulting firms, leading advanced analytics projects in different industries like banking, technology, and consumer goods. Alvaro is also an author and trainer in analytics and data science and has published courses and books, such as 'Become a Python Data Analyst' and 'Hands-On Predictive Analytics with Python'. He has also taught data science and related topics to thousands of students both on-site and online through different platforms such as Springboard, Simplilearn, Udemy, and BSG Institute, among others.
Read more about Alvaro Fuentes