From the course: Artificial Intelligence Foundations: Neural Networks
The Keras Sequential model
- [Instructor] In this chapter, we focus on how to use the Keras library to build regression models. We'll build a simple neural network to reinforce the concepts you have learned. We'll start with an overview of the Keras Sequential API, one of the easiest ways to build, train, and evaluate a neural network. Then, we'll use an actual use case to implement the neural network using Keras. This will require loading and visualizing a dataset and then building the neural network. You'll then have a hands-on challenge lab with a solution that follows. The best way to understand neural networks is to build one for yourself. Let's get started with creating and training a neural network in Keras. By now, you should be very familiar with this multi-layer perceptron neural network, but how would you actually use this to solve a use case or problem? Would you believe that you can implement a simple neural network with just a few lines of code? Shown here is the same neural network, but with code from the Keras Sequential Application Programming Interface or API. Note that for each layer shown in the picture, there is a corresponding line of code: The input layer, hidden layer, and output layer, each have a line of code. This is really all you need to build the model. There are a few additional steps such as compiling and fitting the model, but these two are simple lines of code. Keras is perfect for those that do not have a strong background in deep learning because it is easy to learn. It builds the neural network using a modular approach with minimal code. You can design and iterate on machine learning ideas, moving from experiments to production very quickly. Keras consists of two objects, which means Keras is primarily built of two components, layers and models. Keras supports both recurrent and convolutional networks. Keras also provides support for training on central processing units or CPUs, or graphics processing units or GPUs. Keras offers a number of APIs you can use to define your neural network, including the Sequential API which lets you create a model layer by layer for most problems. It's straightforward, just a simple list of layers in sequence, but it's limited to single-input, single-output stacks of layers. The Functional API is a full featured API that supports arbitrary model architectures. It's more flexible and complex than a Sequential API. It is fully customizable, and it can accept multiple inputs and have multiple outputs. And there's also model subclassing which lets you implement everything from scratch, and this is suitable for research in highly complex use cases, but really rarely used In practice. Using the Sequential API, Keras simply arranges the neural network layers in a sequential order, which means the data flows from one layer to another layer in the given order until the data finally reaches the output layer. The simplest way to build a neural network is to use the Keras Sequential API by using the add layer method as shown here.